Structs are similar to classes in that sense they are also blueprints for objects you want to create in your programs. The main difference is that they are value types—meaning they are passed by value instead of reference, such as classes. We'll go into this in detail in the next section.First, we need to understand how structs work and the specific rules that apply when creating them.
Basic syntax
Structs are declared the same way as classes, and can hold fields, methods, and constructors:
accessModifier struct UniqueName
{
Variables
Constructors
Methods
}
However, structs have a few limitations:
- Variables cannot be initialized with values inside the struct declaration, unless they're marked with the static or const modifier—you can read more about this in Chapter 10, Revisiting Types, Methods, and Classes.
- Constructors without parameters aren't permitted. ...