...

/

C# 6.0-8.0 Nullable Operators

C# 6.0-8.0 Nullable Operators

Use nullable operators to simplify null checks.

So far, we covered that to avoid the NullReferenceException:

  1. We should check for null before accessing the methods or properties of an object.
  2. We should reject null from our methods when they require some parameters.

Let’s look at the new operators C# introduced to simplify our null checks: ?., ??, and ??=. These operators don’t prevent us from having null in the first place, but they help us simplify our work of checking for null values.

Without nullable operators

Let’s start with an example and refactor it to use these new operators.

Let’s ...