C# Data Type

Last modified: July 11, 2021

A C# variable must be a specified data type.

When we declare a data type, system allocated memory to store its value.

Data Type Size Range
byte 1 byte 0 to 255
int 4 bytes -2,147,483,648 to 2,147,483,647
long 8bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes -3.402823e38 to 3.402823e38
double 8 bytes -1.79769313486232e308 to 1.79769313486232e308
decimal 16 bytes (+ or -)1.0 x 10e-28 to 7.9 x 10e28
bool 1 bit True or False
char 2 bytes For example A, B
string 2 bytes per character double, float
DateTime Represents date and time 0:00:00am 1/1/01 to 11:59:59pm 12/31/9999
Example
static void Main(string[] args) { int myNum = 8; string myString = "It is hot"; char myChar = 'D'; double myDouble =6.60D; bool mybool = true; }