On Thu, 14 Aug 2008 18:56:00 -0700, Phill
<Phill@discussi ons.microsoft.c omwrote:
For future reference, if you are asking for help with an error (compile or
execution), you really should post the complete text of the error and be
specific about when and where it happens.
That said, in your code it's clear what's wrong:
If you declare a multi-dimensional array, you have to allocate one. And
you can't allocate just one dimension. A proper allocation would look
like "new int[rows, 8]" (if "rows" contains the number of rows you want)
or "new int[7, 8]" (if you know ahead of time you want 7 rows), or
whatever.
Now, that said, based on the code you posted, it seems as though maybe you
don't really want a multidimensiona l array anyway. In your loop, you are
setting an element of a single-dimension array to an instance of another
single-dimensional array. For that, your array initialization would look
more like this:
double[][] arrULD = new double[][7]; // 7 rows of data
Then the code in your loop would work fine.
Finally, don't forget that C# arrays are 0-based. :)
Pete
<Phill@discussi ons.microsoft.c omwrote:
I have a table that contains 7 row of data with 8 columns. The columns
contain decimal data. Looks like this:
1 .5 .5 0 0 0 0 0 0
2 .25 .25 .25 0 0 0 0 0
etc.
The first column tells me how many points and I will use this as my
index in
the array. I want to load this table into an array to be used in some
calculations and i don't want to have to read the database everytime they
change the number of points to calculate. I am new to c# and am having
a lot
of trouble declaring my array and populating it. This is what I have so
far
but it won't compile because the array is defined wrong..I think???
contain decimal data. Looks like this:
1 .5 .5 0 0 0 0 0 0
2 .25 .25 .25 0 0 0 0 0
etc.
The first column tells me how many points and I will use this as my
index in
the array. I want to load this table into an array to be used in some
calculations and i don't want to have to read the database everytime they
change the number of points to calculate. I am new to c# and am having
a lot
of trouble declaring my array and populating it. This is what I have so
far
but it won't compile because the array is defined wrong..I think???
execution), you really should post the complete text of the error and be
specific about when and where it happens.
That said, in your code it's clear what's wrong:
double[,] arrULD=new int[8];
you can't allocate just one dimension. A proper allocation would look
like "new int[rows, 8]" (if "rows" contains the number of rows you want)
or "new int[7, 8]" (if you know ahead of time you want 7 rows), or
whatever.
Now, that said, based on the code you posted, it seems as though maybe you
don't really want a multidimensiona l array anyway. In your loop, you are
setting an element of a single-dimension array to an instance of another
single-dimensional array. For that, your array initialization would look
more like this:
double[][] arrULD = new double[][7]; // 7 rows of data
Then the code in your loop would work fine.
Finally, don't forget that C# arrays are 0-based. :)
Pete
Comment