I am just trying out a source code. This source code has the following line:
double[][] inputs = sourceMatrix.Submatrix(null, 0, 1).ToArray();
Originally, this "inputs" is filled using a matrix, but I am still too inexperienced to use this matrix. I would first like to test it with some hand-coded values.
Could anybody please tell me how to populate double[][] with some values?
I am not really experienced with C# yet. I guess that [][] means a threedimensional array.
In VB6 I would simply say
Redim inputs(2,2)
and then:
inputs(0,0) = 64
inputs(0,1) = 92
inputs(0,2) = 33
inputs(1,0) = 4
inputs(1,1) = 84
inputs(1,2) = 449
etc...
But I guess it is not that easy in C#. If anybody could help, I would be really glad.
Thank you.
a double[][]
is a jagged array - it is an array of arrays. To fill that you would fill the outer array with a set of double[]
arrays. However, I expect you want a rectangular array: double[,]
, for example new double[3,2]
. There is a short-hand for initializing such arrays:
double[,] data = new double[2, 3] { { 64, 92, 33 }, { 4, 84, 449 } };
double val = data[1, 2]; // 449.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With