Jodll Jodll - 1 year ago 48
C# Question

Create a dictionary with arrays as values

I'm trying to initialize a dictionary with string elements as keys and int[] elements as values, as follows:

System.Collections.Generic.Dictionary<string,int[]> myDictionary;
myDictionary = new Dictionary<string,int[]>{{"length",{1,1}},{"width",{1,1}}};

But the debugger keeps saying: "Unexpected symbol '{'".

Could you tell me what's wrong with the above code?

Thank you!

Answer Source

I am not sure for c# but the following works in Java for example:

instead of



new int[]{1,1}