简体   繁体   中英

convert list<list<string>> to dictionary<list<string>,int>

Dictionary<List<string>, int> dictionary = input.GroupBy(x => x).ToDictionary(x => x.Key, x =>x.Count());

This isn't working, what should I be doing? GroupBy only compares references of list.So how can I compare elements of list?

input is in List< List < string >> and i need it in a dictionary.

Try this

    Dictionary<List<string>, int> dictionary = str.GroupBy(x => x).ToDictionary(x => x.Key, x =>x.Key.Count);

Try this

Dictionary<string, int> dictionary = input.GroupBy(x => x).ToDictionary(x => x.Key.toString(), x =>x.Count());

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