Export (0) Print
Expand All

false

In C#, the false keyword can be used as an overloaded operator or as a literal:

false Operator

User-defined types can define a false operator that returns the bool value true to indicate false and returns false otherwise. 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 false, it must also define operator true.

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 (see 7.11.2 User-defined conditional logical operators).

Example

See the example in 11.4.2 Database boolean type.

false Literal

The false keyword is a literal of type bool representing the boolean value false.

Example

// cs_keyword_false.cs
using System;
class test 
{
   public static void Main() 
   {
      bool a = false;
      Console.WriteLine( a ? "yes" : "no" );
   }
}

Output

no

See Also

C# Keywords | C# Operators | true | Operator Overloading Tutorial

Show:
© 2014 Microsoft