← Back to C# Course | Chapter 2: Variables & Types | Lesson 3 of 7

The bool Type

A bool is a light switch that can only be on or off, true or false. Programs use it to answer yes-or-no questions such as 'is the door open?'.

In this page:

  1. The bool Type
Syntax
csharp
bool variableName = true;
bool result = value1 >= value2;

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

markup
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);
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Writing if (x = true) instead of x == true or just if (x).
  2. Expecting numbers to work as booleans, when C# does not treat 0 or 1 as false or true.
  3. Writing True or TRUE instead of true, since C# keywords are lowercase.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.