相关疑难解决方法(0)

使用foreach同时迭代多个列表(语法糖)

嗨,有没有办法做这样的事情:

for (int i = 0; i < Math.Min(a.Count, b.Count); i++)
{
    // Do stuff
    //a[i]
    //b[i]
}
Run Code Online (Sandbox Code Playgroud)

与Foreach?

因为写一些类似的东西会很好

foreach(var item1 in list1 and var item2 in list2 /* ....*/)
{
   item1.use(item2);
}
Run Code Online (Sandbox Code Playgroud)

编辑

好对不起我对某些人不够清楚,所以希望能有更好的解释

List<classA> listA = fillListA();
List<classB> listB = fillListB();
//here could be infinity many lists of sometimes diffrent T types
Run Code Online (Sandbox Code Playgroud)

现在我想执行某种ForEach因为我不喜欢用for循环做它应该简单明了很好像

foreach(var item1 in list1 and var item2 in list2 /* and ...*/)
{
    item1.use(item2);
}
Run Code Online (Sandbox Code Playgroud)

AFAIK我不能修改这样一个keay词类的东西,所以我认为确定构建像Parallel.ForEach那样的迭代器,ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) …

.net c#

33
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1