true false
suggest changeThe true
and false
keywords have two uses:
- As literal Boolean values
var myTrueBool = true;
var myFalseBool = false;
- As operators that can be overloaded
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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents