开发者

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

开发者 https://www.devze.com 2023-03-16 00:54 出处:网络
Dic开发者_如何学Gotionary<List<string>, int> dictionary = input.GroupBy(x => x).ToDictionary(x => x.Key, x =>x.Count());
Dic开发者_如何学Gotionary<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());
0

精彩评论

暂无评论...
验证码 换一张
取 消