Is it possible to create and initialise a System.Collections.Generic.Dictionary
object with String key/value pairs in one statement?
I'm thinking along the lines of the constructor for an array of Strings..
e.g.
Private mStringArray As String() = {"String1", "String2", "etc"}
In case this is turns out to be a syntactic sugar kind of thing, I'd prefer an answer that I can use in .Net 2.0 (Visual Studio 2005), and Visual Basic - though I'm curious if it's possible at all so don't let that put you off ;o)
Dictionaries are also initialized using the curly braces {} , and the key-value pairs are declared using the key:value syntax. You can also initialize an empty dictionary by using the in-built dict function. Empty dictionaries can also be initialized by simply using empty curly braces.
In C#, Dictionary is a generic collection which is generally used to store key/value pairs. The working of Dictionary is quite similar to the non-generic hashtable. The advantage of Dictionary is, it is generic type.
Like this:
Dim myDic As New Dictionary(Of String, String) From {{"1", "One"}, {"2", "Two"}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With