Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Collections.Generic.Stack: referencia práctica

System.Collections.Generic.Stack: referencia práctica: Stack<T> implementa orden último en entrar, primero en salir mediante Push, Peek y Pop.

Versión: .NET API; verified on .NET 10.0.14

Sintaxis

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

Stack implementa orden último en entrar, primero en salir mediante Push, Peek y Pop.

Úsalo para búsqueda en profundidad, historiales de deshacer y modelado explícito de una pila de trabajo.

No es seguro para escrituras concurrentes y la enumeración observa elementos sin eliminarlos.

Pop y Peek en una pila vacía lanzan InvalidOperationException, mientras TryPop y TryPeek devuelven false.

El programa completo usa realmente System.Collections.Generic.Stack; su stdout esperado exacto es 2.

Ejemplos

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

El programa completo usa realmente `System.Collections.Generic.Stack`; su stdout esperado exacto es `2`.

Fuentes