.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