This code snippet works as expected for the int
type:
public class Test
{
public int Value
{
get => _Value;
set
{
if (_Value != value)
_Value = value;
}
}
private int _Value;
}
When int
is replaced by the generic T
, the compiler complains with:
Operator '!=' cannot be applied to operands of type 'T' and 'T'
Why does this happen and is there a way to solve it?