Monday, June 03, 2013

What is the Difference between Value Type and Reference Type?

Posted by Rahul Kharde at 9:42 AM

Value Type
Reference Type
Reference types can be created at run time.
Reference types can be created at run time.
Store in stack
Store in heap
value types holds the data directly
Reference types holds the data indirectly
Garbage collector can't access the stack
Garbage collector can access heap
Value types cannot contain the value null.
Reference types can contain the value null.
No default values will be stored in value types
Reference types holds default value
When passed as value type new copy is created and passed so changes to variable does not get reflected back
When passed as Reference type then reference of that variable is passed so changes to variable does get reflected back
Value type store real data
Reference type store reference to the data.
Value types are faster in access
Reference types are slower in access.
Value type consists of primitive data types, structures, enumerations.
Reference type consists of class, array, interface, delegates
Value types derive from System.ValueType
Reference types derive from System.Object

Examples for value types: Predefined datatypes, structures, enums
int i, j;
i = 100;
j = 200;

Examples for reference types: Classes, objects, Arrays, Indexers, Interfaces
int i = 100, j;
j = i;



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top