Difference between structure and class

Let us examine the difference between structure and class.

User-defined value types are also called structures or simply structs. Three value types are Built-in types, User-defined types, and Enumerations. Each of these types is derived from System.ValueType base type. When you assign between value-types variables, the data is copied from one variable to the other and stored in two different locations on the stack.

Value-type function as objects and we can call methods on them. Example is the ToString method used when displaying values as text.

As with all vaue types, instances of user defined types are stored on the stack and they contain their data directly. In most other ways structure behave nearly identical to class. The structure can be easily converted to a class (from value type to reference type) bychanging the structure / struct keyword.

While functionality is similar, structure is generally more efficient than class.