Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SelectMany从列表中提取值并传递给组_C#_Linq - Fatal编程技术网

C# 使用SelectMany从列表中提取值并传递给组

C# 使用SelectMany从列表中提取值并传递给组,c#,linq,C#,Linq,我有下面的查询,我在列表中使用SelectMany,然后按列表的“Name”和“Count”分组,并将值存储在“Name”和“Count”中 var groups = originalList.SelectMany(fullList => fullList.ListOfItems, (fullList, details) => new { fullList.Name, fullList.ListOfItems }) .Gr

我有下面的查询,我在列表中使用SelectMany,然后按列表的“Name”和“Count”分组,并将值存储在“Name”和“Count”中

var groups = originalList.SelectMany(fullList => fullList.ListOfItems, (fullList, details) => new { fullList.Name, fullList.ListOfItems })
                               .GroupBy(x => x.Name,
                                x => x.ListOfItems.Count())
                               .Select(g => new { Name = g.Key, Count = g.Count()});

//Do something with results        
foreach (var item in groups)
{
    var name = item.Name;
    var count = item.Count;
}
现在,我想将原始列表中的另一个参数传递给结果组,我们称之为fullList.SomeOtherValue

我如何修改上述内容,使其也能通过

我想以这个结尾:

foreach (var item in groups)
{
    var name = item.Name;
    var count = item.Count;
    var someother = item.SomeOtherValue;  <-- I want this as well
}
foreach(组中的变量项)
{
var name=item.name;
var count=项目计数;

var someother=item.SomeOtherValue;听起来像这样的东西应该可以工作:

originalList.SelectMany(fullList => fullList.ListOfItems)
                .GroupBy(x => new { x.Name, x.SomeOtherValue})
                .Select(g => new { g.Key.Name, g.Key.SomeOtherValue, Count = g.Count()});

听起来像这样的东西应该有用:

originalList.SelectMany(fullList => fullList.ListOfItems)
                .GroupBy(x => new { x.Name, x.SomeOtherValue})
                .Select(g => new { g.Key.Name, g.Key.SomeOtherValue, Count = g.Count()});
奥列克西·阿扎=天才:)在哪里学这些魔术;)奥列克西·阿扎=天才:)在哪里学这些魔术;)