Array of dictionaries in C#

后端 未结 5 1758
挽巷
挽巷 2020-12-15 05:42

I would like to use something like this:

Dictionary[] matrix = new Dictionary[2];

But, when I do:

5条回答
  •  萌比男神i
    2020-12-15 06:13

    Dictionary[] matrix = new Dictionary[2];
    

    Doing this allocates the array 'matrix', but the the dictionaries supposed to be contained in that array are never instantiated. You have to create a Dictionary object in all cells in the array by using the new keyword.

    matrix[0] = new Dictionary();
    matrix[0].Add(0, "first str");
    

提交回复
热议问题