CKTIS / C#
System.Collections.Generic.Stack: odniesienie praktyczne
System.Collections.Generic.Stack: odniesienie praktyczne: Stack<T> implementuje LIFO przez Push, Peek i Pop.
Wersja: .NET API; verified on .NET 10.0.14
Składnia
System.Collections.Generic.Stack /* select a documented member or constructor */Stack implementuje LIFO przez Push, Peek i Pop.
Stosuj do DFS, cofania i jawnego modelowania stosu pracy.
Nie jest bezpieczny dla współbieżnych zapisów; enumeracja nie usuwa elementów.
Pop/Peek pustego stosu zgłasza InvalidOperationException; TryPop/TryPeek zwracają false.
Kompletny program rzeczywiście używa System.Collections.Generic.Stack; oczekiwany stdout to dokładnie 2.
Przykłady
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());
Wynik
2
Kompletny program rzeczywiście używa `System.Collections.Generic.Stack`; oczekiwany stdout to dokładnie `2`.