我在 C# 中工作并使用排序的 List<T>
的结构。我正在尝试遍历 List
对于每次迭代,我都想访问列表的下一个成员。有办法做到这一点吗?
伪代码示例:
foreach (Member member in List)
{
Compare(member, member.next);
}
最佳答案
你不能。改为使用 for
for(int i=0; i<list.Count-1; i++)
Compare(list[i], list[i+1]);
关于c# - 如何在 C# 中的 foreach 循环内访问集合中的下一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2404193/