Value Type and Reference Type in C sharp

Data type are divided into two category

  1. Value Type
  2. Reference Type
1. Value Type:- All fixed length type comes under the categories of value type. Examples :- int , float ,char e.t.c

Fixed length will store their values under stack memory where stack is a data structure that works in a principle first in last out or last in first out. Whenever the execution of program starts, stack get created and given to the program for storing its values. The stack is under the control of operating system. Which get cleared only in the end of program execution. Stack can allocate the memory only in fixed length and no two program can share the same stack.

2.Reference Type :- All variable length types comes under the categories of reference type and by default two predefined reference type are String and Object.
Reference type will store their value under a memory location known as Heap memory which will be under the control of special program known as Garbage Collector.
After storing a value in heap memory the base of memory store in stack so heap is dependent on stack.


Note:-  In Java and .Net language heap is known as managed head because it is managed by the Garbage Collector 

No comments:

Post a Comment