【发布时间】:2011-01-28 19:21:22
【问题描述】:
我正在尝试以下方法:
T value1 = el.value; // it's of type T already
T value2 = default(T);
if (value1 != value2) // gives the following error: Operator '!=' cannot be applied to operands of type 'T' and 'T'
{
// ...
}
那么,我如何比较这两个值?为什么会出现这个错误?
提前致谢!
【问题讨论】:
-
确保 T 实现了 ICompare-ish 类型的类,并且定义 T 的方法或类在声明中具有这些引用。
标签: c# types comparison