[RESOLVED] Easy - Loop through collection of collections
I have a Collection, the keys are strings and the values are Collections. In the sub Collections the keys are strings and values are Singles/Floats.
How would I loop through all of the data? I need to get the keys and values not just the values.
I've tried this but it produces a cast error:
Code:
Dim de As DictionaryEntry
For Each de In MyCol
'key should be in de.Key
'value should be in de.Value
Next
Cheers
Re: Easy - Loop through collection of collections
try this maybe:
Code:
Dim de As DictionaryEntry
de.Key = "Test"
de.Value = "1232"
For Each MyCol In de.Value
MsgBox(de.Value & " " & de.Key)
'key should be in de.Key
'value should be in de.Value
Next
Re: Easy - Loop through collection of collections
Nevemind, solved it by using Hashtables instead of collections
Re: [RESOLVED] Easy - Loop through collection of collections
Using a different method doesn't necessarily answer the question, however...
If it's a Dictionary, you can use a KeyValuePair Structure, Or you can loop through the keys and values (the values in this case are simply objects, but you can make them whatever you like):
Code:
Dim MyDictionary As Dictionary(Of String, Object)
For Each kvp As KeyValuePair(Of String, Object) In MyDictionary
Next
For Each key As String In MyDictionary.Keys
Next
For Each value As Object In MyDictionary.Values
Next