C Sharp Data Types

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

C# Data Types

A data type specifies the type of data that a variable can store such as integer, floating, character etc.

CSHRAP Data types 1

There are 3 types of data types in C# language.

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

Value Data Type

The value data types are integer-based and floating-point based. C# language supports both signed and unsigned literals.

There are 2 types of value data type in C# language.

1) Predefined Data Types - such as Integer, Boolean, Float, etc.

2) User defined Data Types - such as Structure, Enumerations, etc.

The memory size of data types may change according to 32 or 64 bit operating system.

Let's see the value data types. It size is given according to 32 bit OS.

Data Types Memory Size Range
char 1 byte -128 to 127
signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 127
short 2 byte -32,768 to 32,767
signed short 2 byte -32,768 to 32,767
unsigned short 2 byte 0 to 32,767
int 2 byte -32,768 to 32,767
signed int 2 byte -32,768 to 32,767
unsigned int 2 byte 0 to 32,767
short int 2 byte -32,768 to 32,767
signed short int 2 byte -32,768 to 32,767
unsigned short int 2 byte 0 to 32,767
long int 4 byte  
signed long int 4 byte  
unsigned long int 4 byte  
float 4 byte  
double 8 byte  
long double 10 byte

Reference Data Type

The reference data types do not contain the actual data stored in a variable, but they contain a reference to the variables.

If the data is changed by one of the variables, the other variable automatically reflects this change in value.

There are 2 types of reference data type in C# language.

1) Predefined Types - such as Objects, String.

2) User defined Types - such as Classes, Interface.


Pointer Data Type

The pointer in C# language is a variable, it is also known as locator or indicator that points to an address of a value.

CSHRAP Data types 2


Symbols used in pointer

Symbol Name Description
& (ampersand sign) Address operator Determine the address of a variable.
* (asterisk sign) Indirection operator Access the value of an address.

Declaring a pointer

The pointer in C# language can be declared using * (asterisk symbol).

  1. int * a;  //pointer to int      
  2. char * c; //pointer to char