How do I compare a generic type to its default value?

Viewed 7055
void Get<T>(Action<T> createObject)
{
    T obj = createObject();
    if(obj == default(T))
        return obj;

    // .. do a bunch of stuff
    return obj;
}

Compiler error: Operator '==' cannot be applied to operands of type 'T' and 'T'

How do I do this properly?

0 Answers
Related