Are these two lines the same, '? … :' vs '??'?

前端 未结 7 2029
醉梦人生
醉梦人生 2021-01-30 19:28

Is there a difference between these two lines?

MyName = (s.MyName == null) ? string.Empty : s.MyName

or

MyName = s.MyName ?? st         


        
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 19:54

    No. Both are doing the same thing. Second one is efficient. Which returns the actual value if it is not null. Else the right-hand side value will be returned.

    Refer this http://msdn.microsoft.com/en-us/library/ms173224.aspx

    Hope this helps.

提交回复
热议问题