Stage 1 · Lesson 7 of 9
null and nullable reference types
A variable of a reference type can hold null, meaning "no object here". Calling a method on it throws NullReferenceException, the most common crash in C#. New projects turn on .
With them, string means "should never be " and string? means "might be null". The compiler then warns when you use a string? without checking it first. Take those warnings seriously.
The language gives you tools for this: if (name is null), the ?. as in order?.Customer, and the ?? as in name ?? "Guest", which supplies a fallback. Console.ReadLine() returns string?, which is why the compiler warns the first time you use its result. Fix the cause rather than silencing the warning with !.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GuideFreeLearn C#
Microsoft · Beginner
Official C# fundamentals tutorials that you run locally with the .NET SDK
- PlatformFreefreeCodeCamp
freeCodeCamp · Beginner
Free Foundational C# certification, built with Microsoft, with a graded exam at the end