CKTIS / C#
System.Collections.Generic.Stack: referência prática
System.Collections.Generic.Stack: referência prática: Stack<T> implementa a ordem último a entrar, primeiro a sair através de Push, Peek e Pop.
Versão: .NET API; verified on .NET 10.0.14
Sintaxe
System.Collections.Generic.Stack /* select a documented member or constructor */Stack implementa a ordem último a entrar, primeiro a sair através de Push, Peek e Pop.
Usa-o para pesquisa em profundidade, históricos de anulação e modelação explícita de uma pilha de trabalho.
Não é seguro para escritas concorrentes e a enumeração observa os elementos sem os remover.
Pop e Peek numa pilha vazia lançam InvalidOperationException, enquanto TryPop e TryPeek devolvem false.
O programa completo usa realmente System.Collections.Generic.Stack; o stdout exato esperado é 2.
Exemplos
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());
Resultado
2
O programa completo usa realmente `System.Collections.Generic.Stack`; o stdout exato esperado é `2`.