Structs differ from classes in several important ways:
- Structs are value types
- Assignment to a variable of a struct type creates a copy of the value being assigned. This differs from assignment to a variable of a class type, which copies the reference but not the object identified by the reference
- The default value of a struct is the value produced by setting all value type fields to their default value and all reference type fields to null
- Boxing and unboxing operations are used to convert between a struct type and object.
- Instance field declarations for a struct are not permitted to include variable initializers
- A struct is not permitted to declare a parameterless instance constructor
- A struct is not permitted to declare a destructor.
struct Point
{
public int x = 1; // Error, initializer not permitted
public int y = 1; // Error, initializer not permitted
}