I can easily use a string array without declaring it in advance using something like this:
new string[]{"MyString1","MyString2"}
And use it as a method parameter without having to declare a variable for it in advance. However I can’t do this properly with Dictionary<string,string>.
I tried:
new Dictionary<string,string>(){"1","2"}
And
new Dictionary<string,string>().Add("1","2"):
None of above worked in terms of being compiled.
Do it this way
Every Dictionary entry is a combination of a Key and a corresponding value. Hence first entry is
{"Key1","Value1"}where Key is"Key1"and value is"Value1"and so and so forth.This cannot be used for method parameter as
Addmethod does not return anything. Its a void method.Food for thought: Your
new string[]{"MyString1","MyString2"}is single dimensional array namelystring[]whereas dictionary is like string[x][2] where x is length of dictionary. (string[x][2] is just for representation purpose. I know its illegal declaration)