Is this array initialization incorrect?

public byte[][,] Shapes = 
    {
        {
            {1,1}, 
            {1,1}
        }, 
        {
            {1}, 
            {1}, 
            {1}, 
            {1}
        },
        {
            {0,0,1},
            {1,1,1}
        }
    };

I get this error: "Array initializers can only be used in a variable or field initializer. Try using a new expression instead."

I could do this...

public class Shape
{
    public byte[][,] Shapes;

    public Shape()
    {
        Shapes = new byte[3][,];

        Shapes[0] = new byte[2, 2];
        Shapes[0][0, 0] = 1;
        Shapes[0][0, 1] = 1;
        Shapes[0][1, 0] = 1;
        Shapes[0][1, 1] = 1;

        Shapes[1] = new byte[1, 4];
        Shapes[1][0, 0] = 1;
        Shapes[1][0, 1] = 1;
        Shapes[1][0, 2] = 1;
        Shapes[1][0, 3] = 1;
    }
}

But that makes it very hard to add more shapes to my program.

Is my initializer wrong? And if I'm not allowed to do it this way, what's the easiest way to set it out?

8
задан anar khalilov 4 November 2013 в 13:11
поделиться