Stack vs. Heap

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Here are our two golden rules:

  1. A Reference Type always goes on the Heap; easy enough, right?
  2. Value type always goes on the  Stack.

heapvsstack2.gif

 

Value Types:

In C#, all the “things” declared with the following list of type declarations are Value types (because they are from System.ValueType):

  • bool
  • byte
  • char
  • decimal
  • double
  • enum
  • float
  • int
  • long
  • sbyte
  • short
  • struct
  • uint
  • ulong
  • ushort

Reference Types:

All the “things” declared with the types in this list are Reference types (and inherit from System.Object, except, of course, for object which is the System.Object object):

  • class
  • interface
  • delegate
  • object
  • string

 


Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.