我可以用来检索上一个输入位置的最佳或简便容器是什么?

还是有比使用Count更好或更容易的方法?依靠计数可以吗?

例:

List<Class> myList = new List<Class>();
int lastEntry = myList.Count - 1;
Message.Box(myList[lastEntry].Name);


该列表没有并发写入,主要是读取。

最佳答案

对于Count或其他实现List<T>ICollection<T>的其他东西,使用ICollection很好-但是您的代码中有一个off-by-one error。它应该是...

int lastEntry = myList.Count - 1;    // index is zero-based

关于c# - 轻松获得最后进入位置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7956455/

10-11 22:25
查看更多