views:

118

answers:

2

What I would like to do in my code is something like that below:

public static class DataClass
{
    public static byte[,,] Array3d = { { {0,0},{0,0}},{{0,0},{0,0}}};

}

class MyClass
{
    public MyClass()
    {
        someMethod(DataClass.Array3d[0]);
        someMethod(DataClass.Array3d[1]);
    }

    void someMethod(byte[,])
    {
    }
}

I would like to know if there is some way to do what I am trying to when calling someMethod(). If not, what should I do?

+3  A: 

Use a jagged array instead:

static byte[,][] array3d
Lucero
The one that would work in this case is `static byte[][,] array3d`. I tried it here, but it has the big inconvenient that I cannot initialize it the easy way I was planning. I am forced to use `new` operator and the static constructor.
Ricardo Inácio
+1  A: 

You could just pass your 3D-array to the method. There is nothing preventing you from doing only operations on the relevant 2D subsection in the method.

You could also use a jagged array, but that comes at a heavy cost which I'm not sure is acceptable if you use a 3D-array in the first place.

Foxfire
Yes, but then it would cause coupling problems if the array and the method standed in distinct classes, as is in my project here. I will correct the example for a better representation.
Ricardo Inácio