0

I am trying to put two 2D-Arrays in one 3D-Array, this is my current approach. I am wondering why it isn't working:

double[,] l = new double[,]{
    {1,1}
};

double[,] u = new double[,]{
    {2,2}
};
double[,,] lu = new double[,,]
{
    { l },
    { u }
};

This also doesn't work:

double[,][] lu = new double[,][]
{
    { l }, 
    { u }
};
binaryBigInt
  • 1,526
  • 2
  • 18
  • 44

2 Answers2

1

Just do it like this:

double[][,] lu = new[] { l,u };
CSharpie
  • 9,195
  • 4
  • 44
  • 71
  • multi dimensional arrays that mix the two array types are horrible though :/ – will Feb 11 '17 at 10:27
  • @will they are and im not entirly sure why its `[][,]`and not `[,][]` – CSharpie Feb 11 '17 at 10:28
  • Why would it be the other way around? – will Feb 11 '17 at 10:30
  • @CSharpie, MS'es viewpoint, although `[,][]` is more logical for me. – Denis Sologub Feb 11 '17 at 10:30
  • @will usually its `{TYPE}[]` when declaring arrays. TYPE in this case here is `double[,]` – CSharpie Feb 11 '17 at 10:31
  • What's the language you *think in*? – will Feb 11 '17 at 10:31
  • @CSharpie i et the `{TYPE}[]` logic, but that's never applied to arrays, regardless of whatever `[][][,,][][,]` madness you want to create. – will Feb 11 '17 at 10:32
  • @will i never claimed it was, just said i am not sure as to why ms decided to do it like that. – CSharpie Feb 11 '17 at 10:33
  • 1
    @CSharpie, the notation allows you to declare arrays in an intuitive way for calling their indexes. If I have `double[][,] a` (array of 2D arrays [these last also called matrixes]) I will know that `a[0]` is the first 2D array of `a`, and that `a[n][0,2]` is the third `double` element of the first row of `a[n]` – Sam Feb 11 '17 at 10:54
1

I recommend you to take a look at this question, regarding the difference between multidimensional matrixes (like double[,] and double[,,]) and arrays of arrays (like double[][]).

That being said, double[][,] is an array of multidimensional (2D) matrixes, thus each item of it has to be a 2D array, and thus your declaration should be like this:

double[][,] lu = new[] { l, u };
Community
  • 1
  • 1
Sam
  • 1,222
  • 1
  • 14
  • 45