以下内容无法编译:
public void MyMethod<T>(T value)
{
if (value == default(T))
{
// do stuff
}
}
错误:Operator '==' cannot be applied to operands of type 'T' and 'T'
我不能使用value == null,因为T可能是一个结构。
我不能使用value.Equals(default(T)),因为value可能是null。
测试与默认值是否相等的正确方法是什么?