[ACCEPTED]-Creating a dictionary of two-dimensional arrays in c#-c#

Accepted answer
Score: 10

A couple of things here:

Definition must 6 match initialization. You are definining 5 Dictionary and instantiating Dictionary<TKey, TValue>. What 4 this means, based on what you are saying 3 here:

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

I assume this is what you want. If 2 so, your code might be something like this:

    double[] d1 = { 1.0, 2.0 };
    double[] d2 = { 3.0, 4.0 };
    double[] d3 = { 5.0, 6.0, 7.0 };

    double[][] dd1 = { d1 };
    double[][] dd2 = { d2, d3 };

    Dictionary<string, double[][]> dict = new Dictionary<string, double[][]>();
    dict.Add("dd1", dd1);
    dict.Add("dd2", dd2);

If 1 that is it, your issue is solved.

Score: 8

Just gonna update my answer to include the 4 correct declaration as per other answers:

Dictionary<String,double[][]> = new Dictionary<String,double[][]>();

Alsoyours 3 is a array of array and not a MultiDimensional one..Not sure if that's 2 what you want..

If you want a MultiDimensional 1 Array it's

Dictionary<String,double[,]> = new Dictionary<String,double[,]>();
Score: 4

You also have to fully qualify the type 2 of the variable, not only of what you are 1 going to allocate:

Dictionary<String,double[][]> dictLocOne = new Dictionary<String,double[][]>();
Score: 3

Try

var dict = new Dictionary<String, double[,]>();

0

Score: 1

Example:

var d = new Dictionary<string, double[,]>();

d["foo"] = new[,] { { 0.1, 1.0 }, { 0.2, 2.0 1 }, { 0.3, 3.0 } };

More Related questions