Types are reference types. They are stored in the heap memory.
You create objects/instances by using the new keyword. The variables that you use to create the instance of the type stores only the reference to the object in the memory. The reference itself is stored in the stack memory.
You can initialise the fields and properties of types in the following ways:
| Way | Description |
|---|---|
| Field Initialiser | Set a default value for a field or property |
| Constructor Parameter | Write a constructor method |
| Primary Constructor | Use the same syntax for accepting parameters as for methods |
Used to make a property or field mandatory for the user of the class to initialise it.
public required string FirstName { get; set; }
Static classes can't be instantiated and can only contain static members. Can be used for extra functions that don't require instances of that class.
internal- used as the default. The class only exists for the current assembly.public- the class becomes available to other assemblies.