IsNullOrDefault generic helper function for nullable types

I've wrote  IsNullOrDefault generic helper function
 
    public  static bool IsNullOrDefault<T>(this Nullable<T> param) where T : struct
    {
        T deflt = default(T);
        if (!param.HasValue)
            return true;
        else if (param.Value.Equals(deflt))
            return true;
        return false;
    }
, but then realized that there is more short implementation on stackoverflow submitted by Josh
public static bool IsNullOrDefault<T>(this Nullable<T> value) where T : struct 
{ 
   
return default(T).Equals( value.GetValueOrDefault() ); 
} 
 
public static bool IsValue<T>(this Nullable<T> value, T valueToCheck) where T : struct 
{ 
   
return valueToCheck.Equals((value ?? valueToCheck)); 
} 

 
posted @ Friday, June 11, 2010 6:42 PM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«May»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789