相关疑难解决方法(0)

Linq用于嵌套循环

我有一个循环如下:

foreach(x in myColl) 
{
    foreach(var y in x.MyList) 
    {
        result.Add(x.MyKey + y)
    }
}
Run Code Online (Sandbox Code Playgroud)

这意味着在我的内部循环中,我需要访问当前外部元素的属性.

我正在寻找LINQ声明,但我不确定.我试过用它

result = myColl
    .SelectMany(x => x.MyList)
    .SelectMany(x => /* how to get the key of the outer loop here */ + x)
Run Code Online (Sandbox Code Playgroud)

c# linq

13
推荐指数
3
解决办法
6284
查看次数

标签 统计

c# ×1

linq ×1