Logical Operators
In this page:
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
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);
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: