<分区>
对于 int
类型,此代码片段按预期工作:
public class Test
{
public int Value
{
get => _Value;
set
{
if (_Value != value)
_Value = value;
}
}
private int _Value;
}
当 int
被通用的 T
替换时,编译器会报错:
Operator '!=' cannot be applied to operands of type 'T' and 'T'
为什么会出现这种情况,有什么办法可以解决吗?