Weird C# syntax

Viewed 819

I've just found this syntax:

date1 = date2?.ToString("yyyy-MM-dd") ?? date3;

Of course, being the first time I saw such a syntax, I did not understand it. After debugging, I understood that it is equivalent to:

if(date2 != null)
   date1 = date2.ToString("yyyy-MM-dd");
else
   date1 = date3;

My question is: why was this syntax introduced, since it is not legible at all, and it just economizes 3 lines of text?

Edit: my question is about the ? operator, not ??

3 Answers
Related