3
votes

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

4 Answers

5
votes

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];
5
votes
public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];

should be:

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

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
votes

change:

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

to:

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