Posts

Showing posts with the label C# | Struct vs Class

C# | Struct vs Class

Structs are light versions of classes. Structs are value types and can be used to create objects that behave like built-in types. Structs share many features with classes but with the following limitations as compared to classes. Struct cannot have a default constructor (a constructor without parameters) or a destructor. Structs are value types and are copied on assignments. Structs are value types, while classes are reference types. Structs can be instantiated without using a new operator. A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from the System.ValueType, which inherits from System.Object. Struct cannot be a base class. So, Struct types cannot abstract and are always implicitly sealed. Abstract and sealed modifiers are not allowed, and struct members cannot be protected or protected internals. Function members in a struct cannot be abstract or virtual, and the override modifier is allowed only to the over...