简体   繁体   中英

C# LINQ converting a query to dictionary

AC# converting a query to dictionary:

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( ?? );

I do not know what I should put in ( ?? ).

Any help would be appreciated.

Try this:

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM