CKTIS / C#
or: praktična referenca
or: praktična referenca: or združuje vzorce in se ujema, ko se ujema vsaj eden.
Različica: C# language; verified against C# 14 reference
Sintaksa
or /* grammar-specific form */or združuje vzorce in se ujema, ko se ujema vsaj eden.
Uporabite za jedrnat zapis alternativnih vrednosti ali obsegov.
Deklaracija spremenljivke vzorca pod or je napaka CS8780; prevajalnik jo zavrne, tudi če bi obe možnosti vezali isto ime in tip.
Prejšnji širok vzorec lahko naredi poznejše možnosti nedosegljive.
Celoten program dejansko uporabi or; natančno pričakovani stdout je True.
Primeri
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);
Rezultat
True
Celoten program dejansko uporabi `or`; natančno pričakovani stdout je `True`.