Is this the best approach using generics to check for nulls

Posted by user294747 on Stack Overflow See other posts from Stack Overflow or by user294747
Published on 2010-03-16T13:08:24Z Indexed on 2010/03/16 13:16 UTC
Read the original article Hit count: 193

Filed under:
|
public static T IsNull<T>(object value, T defaultValue)
{
  turn ((Object.Equals(value,null)) | (Object.Equals(value,DBNull.Value)) ?
                                      defaultValue : (T)value);
    }

    public static T IsNull<T>(object value) where T :new()
    {
        T defaultvalue = new T();
        return IsNull(value, defaultvalue);

    }

Have tested, and can use against data objects, classes and variables. Just want to know if there is better way to go about this.

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics