LINQ嵌套字典摘要

时间:2015-07-08 00:07:11

标签: c# linq dictionary nested

Dictionary< DateTime,Dictionary< string,double>>

2015/6/1 10:30  table1  300,
                table2  600

2015/6/1 11:25  table1  200

2015/6/2 10:25  table1  200,
                table2  700

我如何获得这些汇总结果

Dictionary< DateTime,Dictionary< string,double>>

2015/6/1   table1  500,
           table2  600

2015/6/2   table1  200,
           table2  700

1 个答案:

答案 0 :(得分:1)

您需要使用SelectMany展平内部词典,之后您可以先在DateTime上应用GroupBy(词典中为Key),然后在结果中再次按{分组} {1}}。最后,您可以将输出投影为Dictionary。这是完整的代码: -

tables

Working Fiddle.