The true
and false
keywords have two uses:
var myTrueBool = true;
var myFalseBool = false;
public static bool operator true(MyClass x)
{
return x.value >= 0;
}
public static bool operator false(MyClass x)
{
return x.value < 0;
}
Overloading the false operator was useful prior to C# 2.0, before the introduction of Nullable
types.
A type that overloads the true
operator, must also overload the false
operator.