I have Window Application in VB.Net. I have following Classes & Enum.
Public Class Page
Public Property Name As String
Public Property PageItems As List(Of PageItem)
End Class
Public Class PageItem
Public Property ItemName As String
Public Property mode As Mode
End Class
Public Enum Mode
Mode1
Mode2
End Enum
In my application I have a List(Of Page) property. One Page may have multiple PageItemand also PageItem.ItemName can be duplicated with different modes. e.g. Application can have a PageItem with Mode1 and Mode2 (Here it’s possible that Mode1 item may in Page(0) and Mode2 item may in Page(1))
My Question is How to find a PageItems List (Same ItemName) which have both Mode1 and Mode2 from a List(Of Page) property using LINQ ?
Example:
Page 1 has 3 Items {Item1, Mode1}, {Item2,Mode1}, {Item3,Mode2}
Page 2 has 2 Items {Item1, Mode2}, {Item4, Mode1}
Here I want a PageItems list which have both mode Mode1 & Mode2. In the above case the result should be {Item1, Mode1}, {Item1, Mode2} (Item1 have both Modes)
As you need “groups of PageItems”, I went for that approach:
Note the final
Selectis reducing the available information. If you remove it you get the pages of each group too.To test this I used your data set except that I had
Item3withMode2(instead of adding a newMode3to the enumeration) and now to test the answer to your question in the comments I changed theItem4toItem3, so that there are two groups returned for my above answer.The answer to “only get a
List(Of PageItems)” is just a change to the lastSelectline: