views:

241

answers:

2

I know a few differences,

  1. Value types are stored on the stack where as reference types are stored on the managed heap.
  2. Value type variables directly contain their values where as reference variables holds only a reference to the location of the object that is created on the managed heap.

Is there any other difference i missed... If so,what are they?

+7  A: 

Please read: The stack is an implementation detail, and don't ever again repeat the canard that stack allocation is what differentiates value types from reference types in .NET. The CLR may choose to allocate a variable anywhere it wants to.

The most important difference is in the assignment semantics. When you assign a value type to a variable (or pass it to a method as an argument), all of the data is copied. When you assign a reference type, only a reference is copied - both references point to the same object instance in memory.

Aaronaught
A: 

As mentioned by Aaronaught and Eric blog post:

Remember the rule, Reference types always goes to the Heap, whereas Value Types always go where they were declared? If a Value Type is declared outside of a method, but inside a Reference Type it will be placed within the Reference Type on the Heap.

Bhaskar