A new video is available on my YouTube channel: Nullable Reference Types and Null Operators in C#. The video is a quick walkthrough of code based on a series of articles I did last year (links below).
Nullable Reference Types and Null Operators in C#
New projects in C# have nullable reference types enabled by default. This helps make the intent of our code more clear, and we can catch potential null references before they happen. But things can get confusing, particularly when migrating existing projects. In this video, we will look at the safeguards that nullability provides as well as the problems we still need to watch out for ourselves. In addition, we will learn about the various null operators in C# (including null conditional, null coalescing, and null forgiving operators). These can make our code more expressive and safe.
The code shows an existing application that can get a null reference exception at runtime. Then we enable nullable reference types to see what that feature does and does not do for us. Then we walk through the potential null warnings and use the various null operators to take care of them.
All in under 13 minutes!
The video is based on a series of articles. If you prefer text (or just want more detail), you can take a look at these:
- Nullability in C# - What It Is and What It Is Not
- Null Conditional Operators in C# - ?. and ?[]
- Null Forgiving Operator in C# - !
- Null Coalescing Operators in C# - ?? and ??=
- C# "var" with a Reference Type is Always Nullable
More videos are on the way.
Happy Coding!
No comments:
Post a Comment