When using Visual Studio 2010 or later, you should use the FROM keyword as follows:
Dim days = New Dictionary(Of Integer, String) From {{0, "string"}, {1, "string2"}}
See: http://msdn.microsoft.com/en-us/library/dd293617(VS.100).aspx
If you need to use a previous version of Visual Studio, and you need to do this often, you can simply inherit the dictionary class and implement it yourself.
It might look something like this:
Public Class InitializableDictionary Inherits Dictionary(Of Int32, String) Public Sub New(ByVal args() As KeyValuePair(Of Int32, String)) MyBase.New() For Each kvp As KeyValuePair(Of Int32, String) In args Me.Add(kvp.Key, kvp.Value) Next End Sub End Class
brendan Nov 03 '09 at 0:18 2009-11-03 00:18
source share