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
|
int i, j;
i = 100;
j = 200;
Examples for reference types:
Classes, objects, Arrays, Indexers, Interfaces
int i =
100, j;
j = i;
Comments
Post a Comment