Monday, May 13, 2013

What is the difference between constant and readonly?


Constant
  • Its value is determine at compilation time and embedded in the IL.
  • Set at compilation time.
  • Can only for define for primitive type.
ReadOnly
  • Its value is initialized at the run-time inside the constructor.
  • Set during run-time.
  • Can be define for value type and reference type.

Monday, May 6, 2013

Difference between reference type and value type

Value Type
  • Allocated on stack
  • Have both representation i.e. boxed form & unboxed form
  • Derived from System.ValueType
  • No Method can be abstract
  • While assigning field by field copy is made.
  • Storage is free as soon as they goes out of scope

Reference Type
  • Allocated on heap
  • Always has boxed formed
  • Derived from any object other than System.ValueTye
  • Methods can be abstract
  • While assigning only memory address is copied
  • Storage is freed using Garbage collection