Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

The bool class in C# is a data type which can store one of two values:

  • true
  • false

Booleans are especially useful when working with conditions.

See Boolean for general information about the uses and representation of boolean data types.

While a boolean could technically store a bool as a single bit, this wouldn't necessarily be optimal for memory layout.

For this reason, booleans in C# are stored as 1 byte in memory.

Keywords: true and false

edit edit source

C# gives us two keywords for the boolean values true and false.

The keywords are, logically, true and false respectively.

bool a = true;
bool b = false;
bool c = Convert.ToBoolean(1); // true
bool d = Convert.ToBoolean(0); // false