Nullable types: best way to check for null or zero in c#
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) { } more as a curiousity than anything, what's the best way to check for both cases? I've added a helper method which is: public static bool nz(object obj) { var parsedInt = 0; var parsed = int.TryParse(obj.ToString(), out parsedInt); return IsNull(obj) || (parsed && parsedInt == 0); } Is there a better way? eglasius I like if ((item.Rate ?? 0) == 0) { } Update 1: You could also define an extension method like: public static bool IsNullOrValue(this double? value,