3

I cant seem to get this syntax correct or any resource that has an example of this.

Am trying something like:

Row = new Dictionary<string, string> [] [{"A":"A"}, {"B":"B"}]

Any idea on this syntax?

asdf
  • 657
  • 1
  • 13
  • 30

2 Answers2

5

You can try this way:

Row = new Dictionary<string, string>[] 
{ 
    new Dictionary<string, string> { {"A", "A"} }, 
    new Dictionary<string, string> { {"B", "B"} } 
};
LazyOfT
  • 1,428
  • 7
  • 20
4

Use the collection initializers for both the array and the inner dictionaries:

var arrayOfDictionaries = new Dictionary<string, string>[] 
{ 
    new Dictionary<string, string>() { {"A", "A"} }, 
    new Dictionary<string, string>() { {"B", "B"} } 
};

You can read more about this syntax on MSDN here, and here.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130