Nullable types: better way to check for null or zero in c#

后端 未结 11 757
孤街浪徒
孤街浪徒 2020-11-30 22:45

I\'m working on a project where i find i\'m checking for the following in many, many places:

if(item.Rate == 0 || item.Rate == null) { }

mo

11条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 23:19

    Don't forget, for strings, you can always use:

    String.IsNullOrEmpty(str)
    

    Instead of:

    str==null || str==""
    

提交回复
热议问题