Posts

Showing posts from April, 2014

c# Value types and reference types

Image
      May be this topic is one the most confusing part in C# and a quick stackoverflow search would return a pretty huge amount of Q&A on this. This writing would be more for my reference as I myself getting confused with this topic overtime and every time I need to do lot of search to get the exact stuffs. So I will consolidate the abstracts here. I will keep the references in the footer so the reader can have a in-depth read on the same. Value Types The typical convention is “ Value types always goes to stack ”. This is an incorrect statement and the statement should be " value types can be stored on the stack and the heap " There are three kinds of storage locations: stack locations, heap locations, and registers. Long-lived objects are always heap locations. Short-lived objects are always stack locations or registers. References and instances of value types are essentially the same thing as far as their storage is concerned; they go on either the