How to make inline array initialization work like e.g. Dictionary initialization?

后端 未结 6 1803
滥情空心
滥情空心 2021-02-12 12:02

Why is it possible to initialize a Dictionary like this:

var dict = new Dictionary() { 
    { \"key1\", 1 },
    { \"         


        
6条回答
  •  [愿得一人]
    2021-02-12 12:20

    You might not see it but it is the same syntax. The only difference is that an array takes elements as an input where a dictionary takes a 2 dimensional array.

    int[] a = new int[]{5,6};
    int[,] a = new int[]{{5,6},{3,6}};
    Dictionary a = new Dictionary{{5,6},{3,6}};
    

提交回复
热议问题