I have read the following statement regarding to the comparison of C# value types
in C# in Depth, Second Edition several times.
page 77,
When a type parameter is unconstrained (no constraints are applied to it), you can use == and != operators, but only to compare a value of that type with null. You can’t compare two values of type T with each other.
…
When a type parameter is constrained to be a value type, == and != can’t be used with it at all.
If I understand (I don’t think so) it correctly, it basically tells me that you cannot
use == or != to compare two value types. Why why why?
It will be better if a simple example can be given for this case. Can someone give me
a little idea what the above paragraph tries to convey?
It simply means this when constraining to a value type (second paragraph)
Without the value-type constraint on the generic, it also says this (first paragraph)
If you constrain
Tto a reference type, you can get away with using==