Structs are a useful thing to know about when writing C#. Here’s an intro to understand and help you use them!
Structs in C# are value types, meaning that they hold their data values directly, whereas classes are reference types, meaning they hold a reference to the object containing their data.
They are very similar to classes, in that they can hold data variables and methods.
- Struct members are public by default.
- Structs don’t require a constructor.
- Structs cannot be inherited from.
- Structs are value types and are stored on the stack, not heap.
- Structs are better for small amounts of data.
- Structs cannot have the protected accessor.