Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

&&: practical reference

&&: practical reference: && returns true only for two true operands and skips the right side after a false left side.

Version: C# operator reference; verified against C# 14

Syntax

left && right

&& returns true only for two true operands and skips the right side after a false left side.

Use it in guards where the right condition is safe only after the left one.

Side effects in the right operand may never happen.

A user type can participate through overloaded & and true/false; nullable bool is not accepted directly.

The complete program actually uses &&; its exact expected stdout is False\nFalse.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

var called = false; bool Check() { called = true; return true; } Console.WriteLine(false && Check()); Console.WriteLine(called);

Result

False
False

The complete program actually uses `&&`; its exact expected stdout is `False\nFalse`.

Sources