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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…