CKTIS / C#
case: praktická referencia
case: praktická referencia: case definuje návestie hodnoty alebo vzoru v príkaze switch.
Verzia: C# language and .NET 10 reference runtime
Syntax
case /* grammar-specific form */case definuje návestie hodnoty alebo vzoru v príkaze switch.
Použite na výslovné varianty s voliteľnou podmienkou when.
Každá sekcia switch sa musí skončiť prenosom riadenia, napríklad break, return, throw alebo goto; viac po sebe idúcich návestí case môže zdieľať jednu sekciu.
Poradie vzorov je dôležité a zatienený case je chyba kompilácie.
Úplný program skutočne používa case; presne očakávaný stdout je two.
Prí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ýsledok
two
Úplný program skutočne používa `case`; presne očakávaný stdout je `two`.