C# : Class vs Struct : Part 9
- Struct is a value type where as class is a reference type.
 - Value type hold there value in memory where as reference type hold the reference to object in memory.
 - Struct are stored in stack, class are stored in heap.
 - When a struct is copied from other struct a new copy is created and modification in one struct does not affect the other.
 - When a class is copied from other class, only a reference variable is copied, both the object point to a same variable in heap. Modification in one variable will affect the other.
 - struct cannot inherit from other struct where as class can inherit from other class.
 
E.g. Struct
    public struct Struct1 
    {
        //your code
    }
E.g. Class
    public class Class1 
    {
        //your code
    }
No comments