C# TutorialLesson 14Free preview
C# Booleans
This lesson is part of C# · All levels
Summary
The bool type only stores true or false, and is the result of a comparison expression or condition. Boolean works like a program switch: the value true makes the block code run. Methods on strings such as Contains also produce bool so that it can be used directly in the if condition.
Key points
- The bool type has only two values, namely true and false.
- A comparison expression like age is greater than 17 produces a bool.
- The logic operator and, or, not combining some boolean conditions.
- String methods such as Contains, StartsWith, and EndsWith yield bool.
- Boolean values can be directly printed, usually appearing as True or False.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.