Value Type and Reference Type

Data type are divided into 2 category :-
  1)Value Type
 2)  Reference Type

  1)Value type  :-
                          In the case of value type data store on the stack .stack is the place where the data stored in fixed length such as int ,float,char etc.stack is the data structure  which will be under the control of the operationg system.which will be work on the LIFO (Last in First Out) or FILO(First In Last Out).
               Every program has its own stack ,and no any other program shate that stack.i.e.whatever execuatio of program start the operating system   will create stack and give it to the program.which get destroy only when the  end of the program execuation.
2)Reference Type :-
                      Reference type are stored on  “ Heap Memory” which is the other place whethere data can be stored.
In  .net  heap is now more managed and called as managed heap which will be under the control of  “ Garbage Collector”.
      C#  support  two predefind reference type
1)Object
2)String
Eg.
  Int x=100;
Float f=3.14f;
String s= ”Hellow”;
                           In the above example the  string s is declared in stack , but the actual data  hellow is in managed heap,and s in the stack can show the address of the Hellow.
  Now we learn Boxing and UnBoxing
Boxing  :-
                      If any value type is stored on the managed heap memory  i.e. Reference type   is called as Boxing.
    Eg.       Int  x = 100;
                   Object  obj=x;
UnBoxing  :-
         If the value type which is stored on heap memory is transferred back into stack again by converting it into value type is called as UnBoxing.
     In the case of unboxing we need to explict conversion.
Eg.
               Int x=100;
          Object obj= x;                              //  Boxing
Int y=convert.toInt32(obj);                //   UnBoxing.
  



if any problem occour frankly leave mail to me dotnetbyabhipatil@gmail.com  or  for more article      visit my blog  dotnetbyabhipatil.blogspot.in

 your feedback and suggestion is always welcome for me.



Previous
Next Post »