What is null safety in C#?
Answer
C# has evolved significantly in handling null. Before C# 8: all reference types could be null — NullReferenceException was the most common runtime error. Nullable Reference Types (C# 8+ — enabled with <Nullable>enable</Nullable> in .csproj): the compiler tracks nullability and warns when you dereference potentially null references. string name; → non-nullable (must not be null). string? name; → nullable (can be null, must check before use). The compiler emits warnings when you access a nullable value without a null check. Null operators: ?? (null coalescing): name ?? "default". ??= (null coalescing assignment): name ??= "default". ?. (null conditional): person?.Address?.Street — returns null instead of throwing if any part is null. ! (null-forgiving): tells compiler to trust you that it's not null (use sparingly).