Shawn Cooke
Shawn Cooke

Reputation: 967

C# create Dictionary of int and arrays

How can I create a dictionary containing ints as keys and arrays as Values. Here is what I have tried on dotnetfiddle.net with no luck:

Dictionary<int, double[]> dict;
double[] prices = new double[20];
dict = new Dictionary<int, prices>();

Dictionary<int, double[]> dict;
dict = new Dictionary<int, new double[20]>();

Dictionary<int, double[]> dict;
dict = new Dictionary<int, double[20]>();

Upvotes: 1

Views: 1134

Answers (1)

D-Shih
D-Shih

Reputation: 46249

You can try this.

Dictionary<TKey,TValue> is a generic type you can only set contracts type on it.

I think you are looking for Add method to add double array.

Dictionary<int, double[]>  dict = new Dictionary<int, double[]>();
dict.Add(1,new double[20]);

Upvotes: 6

Related Questions