Null-condition and null-coalescing operator *vs.* plain boolean notation

后端 未结 2 395
别那么骄傲
别那么骄傲 2021-01-26 02:41

Example 1:

var ca = p.GetCustomAttribute();
return ca?.Point.IsEqual(cp) ?? false;

Example 2:

var ca          


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 03:33

    To answer you question (null != ca) is equal to ca? as ?(this gives more readability and shorter version) it operator just check the value is null or not , Not sure but compiler underthe hood doing same thing , you can check using reflector.

    Just to not both will give you same result and performs also be same , it just compiler of C# which under the hood replace ? with null check.

提交回复
热议问题