认真CS丨堆栈

堆栈(Stack):

代表了一个后进先出的对象集合。当向堆栈列表中添加一项,称为推入元素。当从堆栈列表中移除一项时,称为弹出元素。

堆栈使用方法如下:

Stack<GameObject> objs = new Stack<GameObject>();
objs.Clear();                               //移除 堆栈objs 所有元素
bool isCon = objs.Contains(gameObject);     //判断 堆栈objs 里是否包含此元素
GameObject obj_00 = objs.Peek();            //返回在 堆栈objs 顶部的物体。(不移除)
GameObject obj_01 = objs.Pop();             //移除并返回在 堆栈objs 的顶部的对象。
objs.Push(gameObject);                      //向 堆栈objs 的顶部添加一个对象。
object[] newArray = objs.ToArray();         //复制 堆栈objs 到一个新的数组中。
发布了320 篇原创文章 · 获赞 77 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/weixin_38239050/article/details/103451013
cs