c#中的队列和栈
Queue代表这一个先进先出的对象集合,当你需要对各项进行先进先出访问时,可使用Queue队列。 反之使用Stack 。
不建议将 Queue 类用于新开发。 相反,我们建议使用泛型Queue<T>类。
使用 ConcurrentQueue<T> 或 ConcurrentStack<T> 如果需要同时从多个线程访问集合。
官网文档:
- Queue 类 (System.Collections.Generic) | Microsoft Learn
- Stack 类 (System.Collections.Generic) | Microsoft Learn
- ConcurrentQueue 类 (System.Collections.Concurrent) | Microsoft Learn
- ConcurrentStack 类 (System.Collections.Concurrent) | Microsoft Learn
看这个文档就够了。
更新于:2023.5.25