January 2, 2012

What is the difference between Class and Structure?

Following are the differences between Class and Structure :
  • Structures are value types and classes are reference types. So structures are stored on stack and classes uses heap.
  • Garbage collector terminated objects created from classes. Structures are not destroyed using Garbage collector.
  • Structures do not require constructors while classes require. Usually classes have default parameter less constructors.
  • Since structures not allow inheritance, therefore structures members cannot be declared as protected.

No comments:

Post a Comment