On Mar 28, 9:57 am, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.com> wrote:
> Notice that your inner loop is using the value of the array as the index into
> it. I believe your inner loop should be a more traditional loop, as in for
[quoted text clipped - 30 lines]
>
> - Show quoted text -
FTM is correct, its usally, conceptually, easier to use traditional
loops, in this case. The reasion your code gives a null error
reference is because you never allocate the inner "double[]" (will
need two "new" keywords in your code for a double[][]). To conver a
int[][] to double[][] you can do something like the following.
-------------------
int[][] OurData = { new int[] { 5, 3, 1 }, new int[]
{ 3 }, new int[] { 1, 2, 3, 4, 5 } };
double[][] GraphData = new double[OurData.Length][];
for(int i = 0; i < OurData.Length; i++) {
GraphData[i] = new double[OurData[i].Length];
for(int ii = 0; ii < OurData[i].Length; ii++)
GraphData[i][ii] = (double)OurData[i][ii];
}
-------------------
Alternativly, if you like foreach loops, you can do it the same way
you would a while loop (with manual counters - UntestedCode);
-------------------
int oCounter = 0, iCounter = 0;
foreach(int[] A in GraphData) {
GraphData[oCounter++] = new
double[OurData[oCounter]].Length];
foreach(int B in A) GraphData[oCounter][iCounter++] =
(double)B;
iCounter = 0;
}
-------------------
Cheers, NB