.NET在迭代集合时如何确定项目的顺序?C#针对集合的foreach迭代规则
例如:
list<string> myList = new List<string>();
myList.Add("a");
myList.Add("b");
myList.Add("c");
foreach (string item in myList)
{
// What's the order of items? a -> b -> c ?
}
我需要这个顺序(访问集合成员):
for (int i = 1; i < myList.Count; i++)
{
string item = myList[i - 1]; // This is the order I need
}
我可以放心地使用foreach
与List
?其他类型的收藏呢?
你见过这样的:http://stackoverflow.com/questions/678162/sort-order-when-using-foreach-on-an-array-list-etc – 2011-04-12 08:45:40
你的权利,我没有找到它(投票)。 – Xaqron 2011-04-12 11:21:27