Archive for the ‘Reference Type’ Tag

Value Type and Reference Type   Leave a comment

Value Type:

  • Small type that have their values allocated on the stack in memory.
  • Cannot be null; must always contain data.
  • When passed in method (by val), they are coped as new objects.So the original¬† value will never change only the copy will change.
  • Cost is low on performance and memory because values are small.
  • Derived from system.valuetype and are sealed (it cannot be inherited).

Reference Type:

  • Can consume significant resources but have more features.
  • Can be null and reference to heap-based (.Net managed) objects.
  • When passed in methods (by ref) only a reference to object is passed. Changes to reference data change the source.
  • No wasted resource because a copy of the object is not made.
  • Cost is an issue with performance and memory because references need to be managed by .Net and must be garbage collected.



Posted May 1, 2016 by Izharuddin Shaikh in C#

Tagged with ,

%d bloggers like this: