Ricardo Inacio
Ricardo Inacio

Reputation: 171

Passing 2D part of a 3D multidimensional array as a 2D method parameter array in C#

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?

Upvotes: 1

Views: 493

Answers (2)

Foxfire
Foxfire

Reputation: 5755

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.

Upvotes: 1

Lucero
Lucero

Reputation: 60190

Use a jagged array instead:

static byte[,][] array3d

Upvotes: 3

Related Questions