我有一个 List(Of HashSet(Of String))
。是否有一种清晰的单行 LINQ 方法来获取包含列表条目值中所有字符串的单个 HashSet(Of String)
?
例如,从 3 个哈希集 {"A"}、{"A"、"B"、"C"} 和 {"B"、"C"、"D"} 中,我想要一个哈希集 {"A","B","C","D"}。
我很确定我可以用 .Aggregate()
或 .Accumulate()
做一些事情。
C# 或 VB.NET 的解释同样有用。
最佳答案
你可以只使用SelectMany
.在 C# 中:
var newHashSet = new HashSet<string>(myListOfHashSets.SelectMany(x => x));
在 VB.NET 中:
Dim newHashSet As New HashSet(Of String)(myListOfHashSets.SelectMany(Function (x) x))
关于c# - 如何使用 LINQ 组合 IEnumerable(Of IEnumerable)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21687819/