I asked a question almost identical to this a few days ago via this thread and got awesome replies – The biggest lesson for me (aside from the answer itself) was to create a custom object for my holding data.
So, having now done that, can I ask you experts to please show me the most efficient Linq statement to satisfy my requirements?
My Scenario is as follows:
Suppose I have the following holding class:
Public Class Class_Info
Public Property Teacher As String
Public Property Name As String
Public Property Sex As String
End Class
Then, suppose I have the following in another module:
Dim X as new list(of Class_Info)
With the following elements in the list:
Element.Teacher: Element.Sex: Element.Name:
Teacher 1 Male Whatever Name 1
Teacher 2 Female Whatever Name 2
Teacher 1 Female Whatever Name 3
Teacher 1 Female Whatever Name 4
Teacher 2 Male Whatever Name 5
Teacher 3 Male Whatever Name 6
Teacher 3 Female Whatever Name 7
Teacher 1 Male Whatever Name 8
Teacher 1 Female Whatever Name 9
Teacher 2 Male Whatever Name 10
Now, suppose I want to create the following structure with the following values:
Dim dictTeacherSexName as New Dictionary(Of String, Dictionary(Of String, List(of String)))
Dict1_Key: Dict1_Value / Dict2_Key: Dict2_Value:
Teacher 1 Male Whatever Name 1
Whatever Name 8
Female Whatever Name 3
Whatever Name 4
Whatever Name 9
Teacher 2 ...
How could I create that via Linq in the most efficient way?
Thanks!!!
It is the same as last time, however instead of relying on indexes you can point at your object directly.
You can also do this with a ILookup for cleaner use. You can use a custom class as your lookup object but it will need to implement IComparable.