Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

or: practical reference

or: practical reference: or combines patterns and matches when at least one pattern matches.

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

Syntax

or /* grammar-specific form */

or combines patterns and matches when at least one pattern matches.

Use it to express alternative values or ranges concisely.

Declaring a pattern variable beneath or is error CS8780; the compiler rejects it even if both alternatives would bind the same name and type.

A broad earlier pattern can make later alternatives unreachable.

The complete program actually uses or; its exact expected stdout is True.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

object value = 1; Console.WriteLine(value is 0 or 1);

Result

True

The complete program actually uses `or`; its exact expected stdout is `True`.

Sources