C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: We can loop over each KeyValuePair in the List instance with a For-Each loop construct.
KeyValuePairFor Each, ForVB.NET program that converts Dictionary to List
Module Module1
Sub Main()
' Example dictionary.
Dim dict As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)()
dict("cat") = 1
dict("dog") = 2
dict("mouse") = 3
dict("palomino") = 4
' Call ToList on it.
' ... Use KeyValuePair list.
Dim list As List(Of KeyValuePair(Of String, Integer)) = dict.ToList
' We can loop over each KeyValuePair.
For Each pair As KeyValuePair(Of String, Integer) In list
Console.WriteLine(pair.Key)
Console.Write(" ")
Console.WriteLine(pair.Value)
Next
End Sub
End Module
Output
cat
1
dog
2
mouse
3
palomino
4
And: Second, Lists will use less memory because no internal buckets array is necessary.
List