Google News
logo
C# - Interview Questions
What is the difference between a struct and a class in C#?
Class and struct are both user-defined data types, but have some major differences :
 
Struct :
* The struct is a value type in C# and it inherits from System.Value Type.
* Struct is usually used for smaller amounts of data.
* Struct can’t be inherited from other types.
* A structure can't be abstract.
* No need to create an object with a new keyword.
* Do not have permission to create any default constructor.

Class :
* The class is a reference type in C# and it inherits from the System.Object Type.
* Classes are usually used for large amounts of data.
* Classes can be inherited from other classes.
* A class can be an abstract type.
* We can create a default constructor.
Advertisement