Day 13-Struct

Just Like classes struct can have
  • Private Fields
  • Public Properties
  • Constructors
  • Methods
Difference Between Classes and Struct

  • Struct is a value type where class is a reference type
  • Struct are stored in stack where as classes are stored in heap
  • Value type hold there value in memory where they are declared but reference type holds a reference to object in a memory
  • Value type are destroyed immediately after the scope is lost,where as reference type only the reference variable is destroyed after the scope is lost,The object is later destroyed by garbage collector
  • Struct can't have destructors while class can have 
  • Struct are sealed type