Menu
Coddy logo textTech

Boolean

Part of the Fundamentals section of Coddy's C# journey — lesson 8 of 69.

A boolean type has only 2 possible values: true or false.

To assign a boolean value to a variable, use the keyword bool followed by the variable name:

bool variableTrue = true;
bool variableFalse = false;

In the above example, two boolean variables named variableTrue and variableFalse are initialized with the values true and false, respectively.

Booleans are the building blocks for creating logic in the programs we write.

challenge icon

Challenge

Beginner

Declare a variable named isLoggedIn and assign it the value true.

Cheat sheet

A boolean type has only 2 possible values: true or false.

To declare a boolean variable, use the keyword bool followed by the variable name:

bool variableTrue = true;
bool variableFalse = false;

Try it yourself

using System;

public class Program {
    public static void Main(string[] args) {
        // Type your code below
        bool isLoggedIn = ?
        
        // Don't change the line below
        Console.WriteLine("isLoggedIn = " + isLoggedIn);
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals