Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Collections.Generic.Stack: praktická referencia

System.Collections.Generic.Stack: praktická referencia: Stack<T> implementuje poradie posledný dnu, prvý von pomocou Push, Peek a Pop.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

System.Collections.Generic.Stack /* select a documented member or constructor */

Stack implementuje poradie posledný dnu, prvý von pomocou Push, Peek a Pop.

Použite ho na prehľadávanie do hĺbky, históriu vrátenia zmien a explicitné modelovanie pracovného zásobníka.

Nie je bezpečný pre súbežné zápisy a enumerácia prvky iba pozoruje bez odstránenia.

Pop a Peek na prázdnom zásobníku vyvolajú InvalidOperationException, kým TryPop a TryPeek vrátia false.

Úplný program skutočne používa System.Collections.Generic.Stack; presne očakávaný stdout je 2.

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 stack = new Stack<int>();
stack.Push(1); stack.Push(2);
Console.WriteLine(stack.Pop());

Výsledok

2

Úplný program skutočne používa `System.Collections.Generic.Stack`; presne očakávaný stdout je `2`.

Zdroje