C# bool (Boolean)
The bool
data type is used to store two possible values: true
or false
. It is often used for conditional logic, such as determining whether a condition is met.
Key Concepts
- The
bool
type stores only two values:true
orfalse
. - Booleans are frequently used in
if
statements, loops, and other control structures. - The default value for a
bool
isfalse
.
Example of Using a bool
Code Example
// Declare a boolean variable
bool isTrue = true;
// Output the boolean to the console
Console.WriteLine(isTrue);
Output:
True
Code Explanation: The bool
variable isTrue
is initialized with the value true
. It is printed using the Console.WriteLine()
method.
Output Explanation: The boolean value true
is displayed on the console, which is the value assigned to isTrue
.