Nullable and Required Types
Introduction Since the introduction of nullable reference types in C#, and also with the required keyword, I sometimes see some confusion, which I'm going to address here. This is kind of back to basics, but, yet, here we are! ;-) Reference Types A reference type in C#/.NET is a type that: Are instantiated on the heap Are passed by reference (pointer) Can be null Are declared with the class keyword (can also be record , in latest versions) Meaning, for example, that we can have this (string is a reference type): string str = null; str = "Hello, referece types!"; Value Types On the other hand, value types : Are instantiated on the stack Are passed by value (copied on every method call) Cannot be null Always have a value Are declared using the struct , enum , or record struct keywords Implicitly inherit from System.ValueType Value types are numbers, booleans, bytes, characters, enumerations, and some basic structures such as DateTime , Guid , or T...