CKTIS / C#
System.Collections.Generic.Stack: praktická reference
System.Collections.Generic.Stack: praktická reference: Stack<T> implementuje pořadí poslední dovnitř, první ven pomocí Push, Peek a Pop.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Collections.Generic.Stack /* select a documented member or constructor */Stack implementuje pořadí poslední dovnitř, první ven pomocí Push, Peek a Pop.
Použijte jej pro prohledávání do hloubky, historii vrácení změn a explicitní modelování pracovního zásobníku.
Není bezpečný pro souběžné zápisy a enumerace prvky pouze pozoruje bez odstranění.
Pop a Peek na prázdném zásobníku vyvolají InvalidOperationException, zatímco TryPop a TryPeek vrátí false.
Úplný program skutečně používá System.Collections.Generic.Stack; přesně očekávaný stdout je 2.
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 stack = new Stack<int>();
stack.Push(1); stack.Push(2);
Console.WriteLine(stack.Pop());
Výsledek
2
Úplný program skutečně používá `System.Collections.Generic.Stack`; přesně očekávaný stdout je `2`.