Following are the differences between value types and reference types in C#:
- Value types are stored on the stack where as reference types are stored on the managed heap
- Value type variables directly contain their values where as reference variables holds only a reference to the location of the object that is created on the managed heap
- There is no heap allocation or garbage collection overhead for value-type variables. As reference types are stored on the managed heap, they have the over head of object allocation and garbage collection
- Value types cannot inherit from another class or struct. Value types can only inherit from interfaces. Reference types can inherit from another class or interface
No comments:
Post a Comment