Multidimensional arrays in C# -


i defined multi dimensional array in c#:

int[,] values = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }; 

now values not longer in form in dictionary:

values2.add("keya", new list<float> {1,4}); values2.add("keyb", new list<float> {2,5}); values2.add("keyc", new list<float> {3,6}); 

now i'm trying parse dictionary in 2 dimensional array again, somehow there problems:

list<float> outlist = new list<float>(); values2.trygetvalue(values2.keys.elementat(0) string, out outlist);  int[,] values = new int[outlist.count, values2.keys.count];  (int = 0; < values2.keys.count; i++) {    list<float> list = new list<float>();    values2.trygetvalue(values2.keys.elementat(i), out list);     (int j = 0; j < list.count; j++)    {        values[i, j] = convert.toint32(list.elementat(j));    } } 

this throws innerexception: system.indexoutofrangeexception. why? i'm not able convert values properly.

edit: can assumed values in dictionary have same list length. check somewhere else.

i think it's simple getting either lengths or indexing wrong way round. here's array creation:

int[,] values = new int[outlist.count, values.keys.count]; 

and you're setting values[i, j] i less metrics.keys.count , j less list.count.

you either switch lengths round or set values[j, i] instead. given original statement of array, suspect want latter approach.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -