Stack<T>クラス

Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);

foreach (int value in stack)
{
    Console.Write(value);
} // 321

Console.Write(stack.Pop()); // 3
Console.Write(stack.Pop()); // 2
Console.Write(stack.Pop()); // 1

実装しているインターフェイス

[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class Stack<T> :
    System.Collections.Generic.IEnumerable<T>,
    System.Collections.Generic.IReadOnlyCollection<T>,
    System.Collections.ICollection

メソッド

メソッド 機能
Push(T) 先頭に要素を、追加する
Pop() 先頭の要素を、削除して返す
Peek() 先頭の要素を、削除せず返す
TrimExcess() 実際の要素数が現在の容量の90%未満ならば、容量をその数に設定できる
ToArray() 要素を新しい配列にコピーできる
   
Microsoft Learnから検索