why do we prefer ? to ?? operator in c#?

前端 未结 7 1952
别那么骄傲
别那么骄傲 2020-12-13 09:05

I recently found that we can use ?? operator to check nulls. Please check the below code samples:

   var res = data ?? new data();

This is

7条回答
  •  爱一瞬间的悲伤
    2020-12-13 09:29

    One reason I can think of is that this operator was introduced in .NET 2.0 so the code for .NET 1.1 cannot have it.

    I agree with you, we should be using this more often.

    ref link

提交回复
热议问题