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

前端 未结 7 1925
别那么骄傲
别那么骄傲 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:45

    I would have thought the equivalent of

    var res = data ?? data.toString();
    

    would be

    var res = (data!=null) ? data : data.toString();
    
    0 讨论(0)
提交回复
热议问题