February 20, 2015
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.
- A structure is of value type and a class is of reference type.
- A class can have a destructor, but a structure can’t.
- A class can have an explicit parameterless constructor, but a structure can’t.
- 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.
- 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.