如何知道这是循环的最后一次迭代?

Ter*_*rco 7 c# generics list

有没有一种奇特的方法可以知道你在List中的最后一个循环中而不使用计数器

List<string> myList = new List<string>() {"are", "we", "there", "yet"};

foreach(string myString in myList) {
    // Is there a fancy way to find out here if this is the last time through?
}
Run Code Online (Sandbox Code Playgroud)

Eli*_*ing 9

不,你必须使用常规for(int i=0; i<myList.Length; i++) { ... }循环.