C Sharp Data Types

The type of data that a variable can store is specified by a data type. The type of data can be integer, floating, character, etc. In C# language, there are 3 types of data types.

Types Data Types
Value Data Type short, int, char, float, double etc
Reference Data Type String, Class, Object and Interface
Pointer Data Type Pointers

Value Data Type:

Both the integer-based and floating-point based data types are included in the value data types. Also, both the signed and unsigned literals are supported by the C# language. In C# language, there are 2 types of the value data type.

Predefined Data Types:

Example: Integer, Boolean, Float, etc.

User defined Data Types:

Example: Structure, Enumerations, etc.

According to the 32 or 64-bit operating system, the memory size of data types may also vary. Below we have listed the value data types with size according to the 32 bit OS.

Data Types Range Memory Size
char -128 to 127 1 byte
signed char -128 to 127 1 byte
unsigned char 0 to 127 1 byte
short -32,768 to 32,767 2 byte
signed short -32,768 to 32,767 2 byte
unsigned short 0 to 65,535 2 byte
int -2,147,483,648 to -2,147,483,647 4 byte
signed int -2,147,483,648 to -2,147,483,647 4 byte
unsigned int 0 to 4,294,967,295 4 byte
long ?9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 8 byte
signed long ?9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 8 byte
unsigned long 0 – 18,446,744,073,709,551,615 8 byte
float 1.5 * 10-45- 3.4 * 1038, 7-digit precision 4 byte
double 5.0 * 10-324- 1.7 * 10308, 15-digit precision 8 byte
decimal at least -7.9 * 10?28- 7.9 * 1028, with at least 28-digit precision 16 byte

Reference Data Type:

The actual data stored in a variable is not included in a reference data types. They only contain a reference to the variables. Thus a change in value is automatically reflected by the other variable when the data is changed by one of the variables. In C# language, there are 2 types of reference data types.

Predefined Data Types:

Example: Objects, String.

User-defined Data Types:

Example: Classes, Interface.

Pointer Data Type:

Being a variable, a pointer in C# language is used as a locator or an indicator to point to an address of a value.

Symbols used in pointer:

Symbol Name Uses
& (ampersand sign) Address operator Used to determine the address of a variable.
* (asterisk sign) Indirection operator Used to access the value of an address.

Declaring a pointer:

In C# language, the * (asterisk symbol) is used to declare a pointer.

Example:

int * x; //pointer to int

char * ch; //pointer to char