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

后端 未结 11 748
孤街浪徒
孤街浪徒 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:18

    public static bool nz(object obj)
    {
        return obj == null || obj.Equals(Activator.CreateInstance(obj.GetType()));
    }
    

提交回复
热议问题