C#中的Stack类是什么?
当您需要对项目进行后进先出的访问时,可以使用堆栈。将项目添加到列表时,称为推送项目,将其删除时,称为弹出项目。
让我们看一下C#中的堆栈类的示例-
首先,在堆栈中添加元素。
Stack st = new Stack();
st.Push('H');
st.Push('I');
st.Push('J');
st.Push('K');
st.Push('L');现在计算堆栈中的元素数-
Console.WriteLine("Count: "+st.Count);让我们看完整的代码-
示例
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
Stack st = new Stack();
st.Push('H');
st.Push('I');
st.Push('J');
st.Push('K');
st.Push('L');
Console.WriteLine("Count: "+st.Count);
}
}
}输出结果
Count: 5
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西