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.

TypesData Types
Value Data Typeshort, int, char, float, double etc
Reference Data TypeString, Class, Object and Interface
Pointer Data TypePointers

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 TypesRangeMemory Size
char-128 to 1271 byte
signed char-128 to 1271 byte
unsigned char0 to 1271 byte
short-32,768 to 32,7672 byte
signed short-32,768 to 32,7672 byte
unsigned short0 to 65,5352 byte
int-2,147,483,648 to -2,147,483,6474 byte
signed int-2,147,483,648 to -2,147,483,6474 byte
unsigned int0 to 4,294,967,2954 byte
long?9,223,372,036,854,775,808 to 9,223,372,036,854,775,8078 byte
signed long?9,223,372,036,854,775,808 to 9,223,372,036,854,775,8078 byte
unsigned long0 – 18,446,744,073,709,551,6158 byte
float1.5 * 10-45- 3.4 * 1038, 7-digit precision4 byte
double5.0 * 10-324- 1.7 * 10308, 15-digit precision8 byte
decimalat least -7.9 * 10?28- 7.9 * 1028, with at least 28-digit precision16 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:

SymbolNameUses
& (ampersand sign)Address operatorUsed to determine the address of a variable.
* (asterisk sign)Indirection operatorUsed 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

Content Protection by DMCA.com
Please Share