我认为在 VB.NET 2 中没有开箱即用的方法,但是您可以扩展通用字典以使其按您希望的方式工作。
下面的控制台应用程序说明了这一点:
Imports System.Collections.Generic
Module Module1
Sub Main()
Dim items As New FancyDictionary(Of Integer, String)(New Object(,) {{1, "First Item"}, {2, "Second Item"}, {3, "Last Item"}})
Dim enumerator As FancyDictionary(Of Integer, String).Enumerator = items.GetEnumerator
While enumerator.MoveNext
Console.WriteLine(String.Format("{0} : {1}", enumerator.Current.Key, enumerator.Current.Value))
End While
Console.Read()
End Sub
Public Class FancyDictionary(Of TKey, TValue)
Inherits Dictionary(Of TKey, TValue)
Public Sub New(ByVal InitialValues(,) As Object)
For i As Integer = 0 To InitialValues.GetLength(0) - 1
Me.Add(InitialValues(i, 0), InitialValues(i, 1))
Next
End Sub
End Class
End Module