I´m overloading the lessthan-operator in c# and I`m wondering whether this needs to check for null. Below you can find an Example:
public static bool operator <(MyClass x, MyClass y)
{
if (x == null && y == null)
{
return false;
}
if (x == null)
{
return true; //false?
}
if (y == null)
{
return false; //true?
}
return x.Value < y.Value;
}
Or is this correct:
public static bool operator <(MyClass x, MyClass y)
{
return x.Value < y.Value;
}
I didn´t find any instruction on this. But maybe I missed something.