Saturday 1 July 2017

Difference between Value Type and Reference Type?




Value Type


Reference Type

i)   Value Type variable contains the value
     itself.


i)        Reference Type variable that contains
       reference or address of the actual data.


ii)    Value Type stores data in  stack.

Eg:-

int a = 100;

                       



100           
a
    



Stack memory


iii)      Reference Type stores data in managed
        heap and stores address of the data in
        stack.

Eg:-
              
int a=100;
Object obj1 = a;

                

Heap memory



100



                                                      1002
                                |
                                |
                                |
                                |
                       
   |

  ↓
1002         
obj1
    

100
a
Stack memory

               
                



iv)                 Value Types are:-
a)      Integral types (sbyte, byte, short, ushort, int, uint, long, ulong)
b)      Bool type
c)       Char type
d)      Floating point type (float, double)
e)      Decimal type
f)       Struct types
g)      Enumeration types


iv)                     Reference Types are :-
a)      Object type
b)      Class type
c)       Interfaces
d)      Delegates
e)      String type
f)       arrays


No comments:

Post a Comment

Note: only a member of this blog may post a comment.