Export (0) Print
Expand All

true Operator (C# Reference)

Returns the bool value true to indicate true and returns false otherwise when defined by a user-defined type. This is useful for types that represent true, false, and null (neither true nor false), as used in databases.

Such types can be used for the controlling expression in if, do, while, and for statements and in conditional expressions.

If a type defines operator true, it must also define operator false.

A type cannot directly overload the conditional logical operators (&& and ||), but an equivalent effect can be achieved by overloading the regular logical operators and operators true and false.

For more information, see the following sections in the C# Language Specification:

  • 10.9.1 Unary operators

  • 7.11.2 User-defined conditional logical operators

  • 7.16 Boolean expressions

Community Additions

© 2015 Microsoft