本文介绍了如何访问C#中的foreach循环内的集合中的下一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在C#中工作,并且使用结构体的 List< T>
。我正在尝试遍历 List
,并为每个迭代我想访问列表的下一个成员。有没有办法做到这一点?
I'm working in C# and with a sorted List<T>
of structs. I'm trying to iterate through the List
and for each iteration I'd like to access the next member of the list. Is there a way to do this?
伪代码示例:
Pseudocode example:
foreach (Member member in List)
{
Compare(member, member.next);
}
推荐答案
(int i = 0; i< list.Count-1; i ++)
比较使用for而不是
You can't. Use a for instead
for(int i=0; i<list.Count-1; i++)
Compare(list[i], list[i+1]);
这篇关于如何访问C#中的foreach循环内的集合中的下一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!