The meaning of life is to explore the world

Null-coalesce operator

Posted on By Jason Liu

What is the output of below? 1? 3? 5? 6?\

int? x = null;
int val = 1 + x ?? 2 + 3;
Console.WriteLine(val);

Answer:
5

Explanation:

  • Arithmetic operators have higher precedence
  • 1 + null == null