Reference Types and Values Types: reference types and value types. Of the two, you will run into reference types much more often. Reference types are always allocated from the managed heap, and the c # operator returns the memory address of the object- the memory address refers to the object’s bits. You need to bear in mind some performance considerations when you’re working with reference types. First consider these facts:
The memory must be allocated from the manage heap.
Each object allocated on the heap has some additional overhead members associated with it that must be initialized.
Allocating an object from the manage heap could force a garbage collection to occur
// These two lines compile because C# thinks that
// v 1’ s fields have been initialized to 0.
SomeVal v1 = new SomeVal();
Int 32 a = v1.x;
// These two lines don’t compile because C# doesn’t think that
// v 1’ s fields have been initialized to 0.
SomeVal v1;
Int 32 a = v1.x; // error CS0170: Use of possibly unassigned field
The main advantage of value types is that they’re no allocated in the managed heap. Of course, value types have several limitations of their own when compared to reference types. Here are some of the ways in which value types and reference types differ:
.Value type objects have two representations: an unboxed form and a boxed form. Reference types are always in a boxed form.
Value types are derived from System.ValueType. This type offers the same methods as defined by System.Object. However, System.ValueType overrides the Equals method so that is return true if the values of the two object’s fields match.