← Back to C# Course | Chapter 3: Operators | Lesson 3 of 6

Logical Operators

In this page:

  1. Logical Operators

Logical Operators

Logical operators combine boolean expressions: && (AND), || (OR), and ! (NOT). && and || short-circuit — if the left side already determines the result, the right side is never evaluated. This matters when the right side has side effects.

Note: Short-circuiting lets you safely write if (obj != null && obj.IsValid) without a null-check exception.

Example: Logical Operators

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        bool isLoggedIn = true;
        bool isAdmin = false;

        Console.WriteLine(isLoggedIn && isAdmin);
        Console.WriteLine(isLoggedIn || isAdmin);
        Console.WriteLine(!isAdmin);
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 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.