C#Arraylist Confusion需要帮助 [英] C# Arraylist Confusion need help

查看:88
本文介绍了C#Arraylist Confusion需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不再需要在这里,因为我自己解决了它

This no longer needs to be here as I have solved it myself

推荐答案

当你在'addFirst中指定vals [0]时,你覆盖无论其中包含什么价值。



将数组(或ArrayList?)转换为等效的LIFO(上一个,第一个) out)stack,当.NET为你准备好在System.Collections.Generic库中使用时。
When you assign to vals[0] in 'addFirst, you overwrite whatever value is in it.

It's more work than necessary to turn an Array (or ArrayList ?) into the equivalent of LIFO (last in, first out) stack, when .NET gives you one ready to use in the System.Collections.Generic Library.
// create a new integer Stack
private Stack<int> intStack = new Stack<int>();

// somewhere in your code:

// add a value to the Stack
intStack.Push(100);

// return the value at the top of the Stack
int TopInt = intStack.Peek();

// remove and return the value at the top of the Stack
int TopInt = intStack.Pop();

你是什么通过使用堆栈放弃是使用索引来访问不在堆栈顶部的特定元素的任何方式。

What you give up by using a Stack is any way to use an index to access a particular element that is not on "top" of the Stack.


这篇关于C#Arraylist Confusion需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆