Like many programming languages, C# has its own data type system that is used to create variables. The data type defines the internal representation of the data, the set of values that an object can take, and the allowed actions that can be performed on the object.
The C# language has the following basic data types:
bool: stores true or false (boolean literals). Represented by the system type System.Boolean
byte: stores an integer from 0 to 255 and occupies 1 byte. Represented by the system type System.Byte
sbyte: stores an integer from -128 to 127 and occupies 1 byte. Represented by the system type System.SByte
short: stores an integer from -32768 to 32767 and occupies 2 bytes. Represented by the system type System.Int16
ushort: stores an integer from 0 to 65535 and occupies 2 bytes. Represented by the system type System.UInt16
int: stores an integer from -2147483648 to 2147483647 and occupies 4 bytes. Represented by the System.Int32 system type. All integer literals represent values of type int by default:
uint: stores an integer from 0 to 4294967295 and occupies 4 bytes. Represented by the system type System.UInt32
long: stores an integer from -9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 and occupies 8 bytes. Represented by the system type System.Int64
ulong: stores an integer from 0 to 18446744073709551615 and occupies 8 bytes. Represented by the system type System.UInt64
float: stores a floating point number from -3.4*1038 to 3.4*1038 and takes 4 bytes. Represented by the system type System.Single
double: Stores a floating Point number from ±5.0*10-324 to ±1.7*10308 and occupies 8 bytes. Represented by the system type System.Double
decimal: stores a decimal fractional number. If used without a decimal point, it has a value of ±1.0*10-28 to ±7.9228*1028, can store 28 decimal places, and occupies 16 bytes. Represented by the system type System.Decimal
char: Stores a single Unicode character and occupies 2 bytes. Represented by the System.Char system type. Character literals correspond to this type:
string: stores a set of Unicode characters. Represented by the System.String system type. This type corresponds to string literals.
object: can store a value of any data type and takes up 4 bytes on a 32-bit platform and 8 bytes on a 64-bit platform. Represented by the System.Object system type, which is the base type for all other .NET types and classes.
References:
1.Microsoft
Top comments (1)
👍👍👍