Difference Between Structure and Class in C#

Difference Between Structure and Class in C#
Rating: 5 - 1 Votes

Difference Between Structure and Class in C#

Difference Between Structure and Class in C#

Difference Between Structure and Class in C#

We have seen how a class and a structure work.  They are pretty much similar in their functionality, but there are also certain differences between them.  The 5 important differences are given below.

  1. A structure is of value type and a class is of reference type.
  2. A class can have a destructor, but a structure can’t.
  3. A class can have an explicit parameterless constructor, but a structure can’t.
  4. A structure cannot inherit from a class, but it can inherit from an interface.  A class can inherit from both, an another class as well as an interface.
  5. A structure by default is of sealed type, but a class can be or cannot be of sealed type.  To mark a class sealed, you can use sealed keyword.  After marking a class sealed, you cannot use it as a base class for other classes.