CKTIS / C#
goto: praktická reference
goto: praktická reference: goto přenese řízení na návěští v povoleném rozsahu nebo na switch case.
Verze: C# language; verified against C# 14 reference
Syntaxe
goto /* grammar-specific form */goto přenese řízení na návěští v povoleném rozsahu nebo na switch case.
Použijte výjimečně k opuštění složitého stavového automatu, je-li jednodušší struktura horší.
Komplikuje analýzu toku a nesmí vstoupit do rozsahu s neinicializovanými locals.
Přenos stále respektuje finally; návěští musí být ve stejné funkci.
Úplný program skutečně používá goto; přesně očekávaný stdout je 1.
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 = 1; goto Done; value = 2; Done: Console.WriteLine(value);
Výsledek
1
Úplný program skutečně používá `goto`; přesně očekávaný stdout je `1`.