Pro EP 41 : NULL Operators Guide in C#

Muhammad Waseem
Become .NET Pro !
2 min readApr 23, 2023

- Ternary Operator (? :)
- Null Forgiving Operator (!.)
- Null Conditional Operator (?.)
- Null Coalescing Operator (??)
- Null Coalescing Assignment Operator (??=)

Ternary Operator or Conditional Operator(?.) is used to evaluate a condition and then we can do something on that basis for true and false

Null Forgiving or Null Suppression Operator (!.) is used to suppress all nullable warnings for preceding expression. It has no effect on runtime.

Null Conditional Operator (?.) is used to check if an object/property is null or not. If not, null original value is returned otherwise null is returned.

Null Coalescing Operator (??)returns the value of its left-hand operand if it isn’t null; otherwise, it evaluates the right-hand operand and returns its result

Null Coalescing Assignment Operator (??=) assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null. The ??= operator doesn’t evaluate its right-hand operand if the left-hand operand evaluates to non-null

Whenever you’re ready , there are 3 ways I can help you

  1. Subscribe my Weekly .NET Newsletter of C#/.NET with 1950+ Software Engineers.
  2. Promote yourself to 1950+ subscribers by sponsoring my newsletter (Reach me at mwaseemzakir@gmail.com)
  3. Download my eBook at Gum road that contains 30+ .NET Tips (With 950+ Downloads)

--

--