Datatype specifies the type of data which variable can hold. For strongly typed programming languages such as C Sharp, you need to specify the datatype at the time of declaring a variable. In C sharp, datatypes are divided into three.

  • Value data type
  • Reference data type
  • Pointer data type

Value data type

The value data type includes char, int, float, boolean etc. A value can be assigned to these types of variables directly. The value data type is further divided as:

  • Pre-defined data types and
  • User-defined data types.
char1 byte -128 to 127
unsigned char1 byte0 to127
short2 byte -32,768 to 32,767
unsigned short2 byte 0 to 65,535
int4 byte -2,147,483,648 to -2,147,483,647
unsigned int4 byte 0 to 4,294,967,295
long8 byte 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long8 byte 0 – 18,446,744,073,709,551,615
float4 byte
double8 byte

Reference data type

The reference data type does not contain the actual data, but instead, it holds references to the variables. string is an example for reference data types.

Pointer data types

A pointer is declared in C sharp using asterisk symbol (*).  they hold the memory location of other variables.

chr* my_variable;