C# Data Types
Data types define the type of data that a variable can store. A variable in C# must be a specified data type.
C# supports a variety of data types, which can be broadly categorized into two main groups:
Value Types and Reference Types.
Here is an overview of some commonly used data types in C#.
1. Value Types
Numeric Types:
byte
: 8-bit unsigned integer.
sbyte
: 8-bit signed integer.
short
: 16-bit signed integer.
ushort
: 16-bit unsigned integer.
int
: 32-bit signed integer.
uint
: 32-bit unsigned integer.
long
: 64-bit signed integer.
ulong
: 64-bit unsigned integer.
float
: 32-bit floating-point.
double
: 64-bit floating-point.
decimal
: 128-bit decimal.
Character Types:
char
: 16-bit Unicode character.
Boolean Type:
bool
: Represents true or false.
Structs:
User-defined value types.
2. Reference Types
Class Types:
class
: Reference type that can contain data members (fields), methods, properties, and events.
Interface Types:
interface
: Defines a contract for classes that implement it.
Array Types:
Array
: Represents a collection of elements of the same type.
String Type:
string
: Represents a sequence of characters.
Delegate Types:
delegate
: Represents a reference to a method.
Object Type:
object
: The ultimate base class for all types in C#.
Nullable Types:
Allow value types to have a value of null
.
Dynamic Type:
dynamic
: Represents an object whose operations will be resolved at runtime.
These are some of the fundamental data types in C#. Depending on the version of C# and the specific requirements of your program, there may be additional types and features available. C# also supports user-defined data types through the use of classes and structures.