C# tutorials

Updated : Oct 04, 2020 in Articles

Value type and reference type in c#

 1. Value type  

The data types which are capable of storing the data directly into their memory locations are known as “value type”.

Ex: int a=10;       a=>10.

2.Refrence Type:

The data types which can’t store the data directly rather refer to other memory locations where data will be stored are known as “reference types”.

Ex:string s=”welcome”;

What is Difference b/w value type and Reference type?

Value type:

Store the data directly into their memory location

Memory is allocated at compile time

Memory allocated is made in stack i.e. continuously memory location

CLR doesn’t provide automatic memory management

Occupies less memory

If the data is initialized, then stores the default values into the variable

ex: int a;  a=>0

Reference type:

Do not store the data type directly into their memory location. rather than refers to other memory location where data is stored

Memory is allocated at runtime

Memory allocations are made within the heap i.e. random memory allocations.

Reference type in c#

CLR provides automatic memory management

Occupies heap memory. A single reference type variable can occupy a maximum of up to 2GB of memory

If the data is not initialization then stores the null reference the variable

ex: string s;   s=> null

Latest posts by DuttaluruVijayakumar (see all)
Like Love Haha Wow Sad Angry

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x