3

I have the following code:

static int gridX = 40;
static int gridY = 40;

public struct CubeStruct
{
    public Transform cube;
    public bool alive;
    public Color color;
}

public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];

This returns the following errors:

error CS1519: Unexpected symbol `,' in class, struct, or interface member declaration

error CS0178: Invalid rank specifier: expected ,' or]'

error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration

It's probably something obvious, but I can't see it.

4 Answers 4

5

In C#, the [,] go before the name of the variable (i.e. it is not like in C/C++).

public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];
Sign up to request clarification or add additional context in comments.

1 Comment

I'm quite ashamed that I missed it.. Thanks!
5
public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];

should be:

public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];

Comments

3

In C#, nothing can float around outside of a Type. So you need to do this:
Also note that the [,] comes after the type, not after the identifier.

public class GridMain
{
    static int gridX = 40;
    static int gridY = 40;
    public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];

}

public struct CubeStruct
{
    public Transform cube;
    public bool alive;
    public Color color;
}

2 Comments

Of course, my code is IN a class. I just copy/pasted the relevant bit.
sure, that wasn't clear from your question. Thanks for clarifying.
2

change:

public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];

to:

public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.