The bool Type
In this page:
The bool Type
A bool holds either true or false and is the result of every comparison and logical expression. Booleans drive if statements, loops, and conditional logic throughout C#. Unlike some languages, C# never implicitly converts numbers to booleans.
Note: Comparison operators like ==, >, and < always evaluate to a bool.
Example: The bool Type
using System;
class Program
{
static void Main(string[] args)
{
bool isActive = true;
bool hasPermission = false;
bool isAdult = 20 >= 18;
Console.WriteLine(isActive);
Console.WriteLine(hasPermission);
Console.WriteLine(isAdult);
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: