我有 SortedDictionary<int, Dictionary<string, HashSet<long>>>
如何使用 Linq 展平結果?
我試過了:
var result = dictionary.Values.SelectMany(x => x);
但是我如何壓平到最底部?
我需要收集 int, string, HashSet<long>
uj5u.com熱心網友回復:
您可以使用以下內容:
var flattened = dictionary.SelectMany(x => x.Value.Select(y => (x.Key, y.Key, y.Value)));
這將產生一個 IEnumerable ValueTyple<int, string, HashSet<long>>。
請注意,因為這里的型別是IEnumerable,它尚未具體化。您可能希望.ToList()在末尾添加 a (在這種情況下,型別將為List<ValueTyple<int, string, HashSet<long>>>)或將其轉換為您想要的任何其他集合型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/324905.html
下一篇:LINQJOIN性能優化
