0

I have a class, which is stored in a list inside a dictionary, like this:-

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

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

I then need to extract some of these lists and convert them into a single list. I can extract the necessary lists like this:-

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

but cannot then convert these to

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

I've had a look at the questions here and here using SelectMany but I can't get anything using SelectMany to compile, and the C# usage (and explanations) are a little terse.

Using

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

just creates another list of lists.

Does anyone know how to do this?

Community
  • 1
  • 1
Brian Hooper
  • 21,544
  • 24
  • 88
  • 139

1 Answers1

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

In query syntax:

Dim items = From list In list_of_lists
            From item In list
            Select item
Dim list_of_items As List (Of MyClass) = items.ToList()
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939