C#LINQ将查询转换为字典

时间:2014-02-09 23:42:36

标签: c# linq c#-4.0 dictionary windows-7

将查询转换为字典的C#:

public class myClass
{
    public int my_id;
    public Dictionary<string, Dictionary<string, string[]>> myDict;
}

Dictionary<string, myClass> dataDict;

Dictionary<int, Dictionary<string, myClass>> query = (from happen in dataDict 
                     group happen by happen.Value.my_id into g 
                     select g).ToDictionary( ?? );

我不知道应该放什么(??)。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

试试这个:

var query = (from happen in dataDict
            group happen by happen.Value.my_id into g select g)
           .ToDictionary(g => g.Key, g => g.ToDictionary(x => x.Key, x => x.Value));