Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

||: practical reference

||: practical reference: || returns true after the first true operand and skips the right side.

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

Syntax

left || right

|| returns true after the first true operand and skips the right side.

Use it for alternative conditions and safe short-circuit evaluation.

The right function may never run, so do not place required effects there.

A user type can participate through | and true/false; lifted nullable values use different operators.

The complete program actually uses ||; its exact expected stdout is True\nFalse.

Examples

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

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

Result

True
False

The complete program actually uses `||`; its exact expected stdout is `True\nFalse`.

Sources