C
Chris
To me, this seems rather redundant. The compiler requires that if you
overload the == operator, you must also overload the != operator. All I do
for the != operator is something like this:
public static bool operator !=(MyType x, MyType y)
{
return !(x == y);
}
That way the == operator handles everything, and extra comparing logic isn't
needed. I think the C# compiler should NOT allow overloading of the !=
operator, and instead just emit the code I just showed.
I could be completely off my rocker, but this has puzzled me for some time
now, and I just had to ask if someone knows the purpose of allowing the !=
operator to be overloaded.
Chris
overload the == operator, you must also overload the != operator. All I do
for the != operator is something like this:
public static bool operator !=(MyType x, MyType y)
{
return !(x == y);
}
That way the == operator handles everything, and extra comparing logic isn't
needed. I think the C# compiler should NOT allow overloading of the !=
operator, and instead just emit the code I just showed.
I could be completely off my rocker, but this has puzzled me for some time
now, and I just had to ask if someone knows the purpose of allowing the !=
operator to be overloaded.
Chris