Nullable warnings
Context: When nullable annotations are enabled, the compiler produces warnings for potentially unsafe null operations.
Common warnings
Section titled “Common warnings”- CS8618: Non‑nullable property uninitialized
- CS8600: Converting null literal to non‑nullable type
- CS8602: Dereference of a possibly null reference
- CS8625: Cannot convert null literal to non‑nullable type
Fixing warnings
Section titled “Fixing warnings”public class Person{ public string Name { get; set; } // CS8618}// Fix: initializepublic class Person{ public string Name { get; set; } = "";}Using nullable checks
Section titled “Using nullable checks”string? name = GetName();if (name != null){ int length = name.Length; // no warning}// Or using null‑conditional operatorint? length = name?.Length;Real-world usage example
Section titled “Real-world usage example”Team coding standards: Enforce nullable warnings as errors in CI/CD to prevent null reference exceptions in production.
Example: In a GitHub Actions workflow, add -p:WarningsAsErrors=nullable to dotnet build.