簡體   English   中英

轉換列表<list<string> &gt; 到字典<list<string> ,整數&gt; </list<string></list<string>

[英]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());

這不起作用,我該怎么辦? GroupBy 只比較列表的引用。那么如何比較列表的元素呢?

輸入在 List< List < string >> 中,我需要它在字典中。

嘗試這個

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

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM