E
Ethan Strauss
Guest
I am just curious about this. I don't have any particular difficulty dealing with it.
When defining "==" for an object, you also need to define "!=". Why is this? Isn't "!=" always completely implied by "=="? (and for that matter by "Equals")? I have never defined != in any way other than
public static bool operator !=(object obj1, object obj2)
{
return !(obj1 == obj2);
}
And if there is some circumstance that you might want them to be different, wouldn't it make sense to have defining != be optional?
Thanks,
Ethan
Ethan Strauss
Continue reading...
When defining "==" for an object, you also need to define "!=". Why is this? Isn't "!=" always completely implied by "=="? (and for that matter by "Equals")? I have never defined != in any way other than
public static bool operator !=(object obj1, object obj2)
{
return !(obj1 == obj2);
}
And if there is some circumstance that you might want them to be different, wouldn't it make sense to have defining != be optional?
Thanks,
Ethan
Ethan Strauss
Continue reading...