I defined this multidimensional array in C #:
int[,] values = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };
Now the values are no longer in this form, but in the 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 again to parse this dictionary into a two-dimensional array, but for some reason there are problems:
List<float> outList = new List<float>();
values2.TryGetValue(values2.Keys.ElementAt(0) as string, out outList);
int[,] values = new int[outList.Count, values2.Keys.Count];
for (int i = 0; i < values2.Keys.Count; i++)
{
List<float> list = new List<float>();
values2.TryGetValue(values2.Keys.ElementAt(i), out list);
for (int j = 0; j < list.Count; j++)
{
values[i, j] = Convert.ToInt32(list.ElementAt(j));
}
}
This throws an InnerException: System.IndexOutOfRangeException. But why? I cannot convert values correctly.
Edit: it can be assumed that all values in the dictionary have the same list length. I check it somewhere else.
anon
source
share