Interview Part 2

Difference between Class and Struct

Class :

  1. Classes are reference types, allocated on the heap and garbage-collected. 
  2. Can support inheritance
  3. The reference can be null
  4. reference type only the variable destroy after the scope is lost. 
  5. classes can have destructors.
  6. Classes can contain constructor or destructor.
  7. Class has limitless features.
  8. Classes used new keyword for creating instances.

Struct :

  1. Structs are value types, allocated either on the stack or inline in containing types.
  2. Cannot support inheritance
  3. Cannot have a null reference
  4. Value types destroyed immediately after the scope is lost.
  5. Structs are sealed type.
  6. A structure couldn't be null like a class.
  7. Structs can not have destructors,
  8. Structure does not contain constructor or destructor.
  9. Struct has limited features.
  10. Can’t have modifiers like abstractsealed, and static,class
  11. Struct can create an instance, without new keyword.