Value Type and Reference Type

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.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s