Lesson 12: Booleans & comparison
Before making decisions in code, you need yes/no questions. The bool type holds exactly two values: true or false (lowercase in C#). Comparison operators produce a bool: == (equal?), != (not equal?), <, >, <=, >=. Note a critical difference: == checks equality, while = only assigns a value.
bool is a switch with two states: on (true) or off (false). A comparison like 5 > 3 returns one of the two states.
- bool
- A type holding only true or false. In C# the values are written lowercase.
- equality ==
- Checks if two values are equal, returning a bool. Different from = (assignment).
- comparison operators
- == != < > <= >= — all return true or false.
- printing a bool
- Console.WriteLine of a bool shows True or False (capitalized), even though the value is written lowercase.