1

I have a list of MenuItems, each MenuItem has a further list of MenuItems thereby creating hierarchical list

Public Class MenuItemViewModel

    Public Property MenuItems As New ObservableCollection(Of MenuItemViewModel)

End Class

Now, I need to have all objects of type MenuItemViewModel in a flatList. I know I can do recursion to solve this but I was hoping if I can use LINQ to create a list like this.

I tried to do it with selectMany but it doesn't seem to work in my case

MenuItemViewModels.SelectMany(Of MenuItemViewModel)(Function(f) f.MenuItems)

as this will only return a list till one level

Can you please tell me if this is possible using LINQ or any other way ?

Thanks

Muds
  • 4,006
  • 5
  • 31
  • 53

0 Answers0