Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

case: praktická reference

case: praktická reference: case definuje návěští hodnoty nebo vzoru v příkazu switch.

Verze: C# language and .NET 10 reference runtime

Syntaxe

case /* grammar-specific form */

case definuje návěští hodnoty nebo vzoru v příkazu switch.

Použijte pro výslovné varianty s volitelnou podmínkou when.

Každá sekce switch musí skončit přenosem řízení, například break, return, throw nebo goto; více po sobě jdoucích návěští case může sdílet jednu sekci.

Pořadí vzorů je důležité a zastíněný case je chyba kompilace.

Úplný program skutečně používá case; přesně očekávaný stdout je two.

Příklady

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;

var value = 2; switch (value) { case 1: Console.WriteLine("one"); break; case 2: Console.WriteLine("two"); break; }

Výsledek

two

Úplný program skutečně používá `case`; přesně očekávaný stdout je `two`.

Zdroje