堆栈集合类型

System.Collections.Stack 类以及 System.Collections.Generic.Stack<T>System.Collections.Concurrent.ConcurrentStack<T> 泛型类都是先进先出集合类,它们实现 ICollection 接口。 System.Collections.Generic.Stack<T>System.Collections.Concurrent.ConcurrentStack<T> 泛型类还实现 ICollection<T> 泛型接口。

当需要临时存储信息时,也就是说,当想在检索了元素的值后放弃该元素时,堆栈和队列都很有用。 如果需要按照信息存储在集合中的顺序来访问这些信息,请使用 System.Collections.Queue。 如果需要以相反的顺序访问这些信息,请使用 System.Collections.Generic.Stack<T>

如果需要从多个线程并发访问集合,请使用 System.Collections.Concurrent.ConcurrentStack<T>System.Collections.Concurrent.ConcurrentQueue<T> 类型。

System.Collections.Generic.Stack<T> 常用于在调用其他过程期间保留变量状态。

可以对 System.Collections.Generic.Stack<T> 及其元素执行三种主要操作:

请参见

参考

Stack

System.Collections.Generic.Stack<T>

Queue

System.Collections.Generic.Queue<T>

ICollection

System.Collections.Generic.ICollection<T>

ConcurrentStack<T>

ConcurrentQueue<T>

概念

常用的集合类型