转换列表(列表(类))到列表(类)

时间:2015-08-21 10:13:20

标签: vb.net linq list

我有一个类,它存储在字典中的列表中,如下所示: -

Public Class MyClass
    Public something As Integer
    Public something_else As Double
End Class

Dim my_dictionary As Dictionary (Of Integer, List (Of MyClass))

然后我需要提取其中一些列表并将它们转换为单个列表。我可以像这样提取必要的列表: -

Dim list_of_lists As List (Of List (Of MyClass)) =
    From dict_item As KeyValuePair (Of Integer, List (Of MyClass) In my_dictionary
        Where dict_item.Key < some_value
        Select dict_item.Value).ToList

但不能将这些转换为

Dim list_of_items As List (Of MyClass) = ...er...

我已经使用SelectMany查看了问题herehere,但我无法使用SelectMany进行编译,并且C#用法(和解释)有点简洁。

使用

(From one_list In list_of_lists
    Select one_list.FindAll(Function(x) True)).ToList

只创建另一个列表列表。

有谁知道怎么做?

1 个答案:

答案 0 :(得分:2)

Dim list_of_items As List (Of MyClass) = list_of_lists.SelectMany(Function(list) list).ToList()

在查询语法中:

Dim items = From list In list_of_lists
            From item In list
            Select item
Dim list_of_items As List (Of MyClass) = items.ToList()