Reputation: 3005
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.
Upvotes: 3
Views: 782
Reputation: 15803
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;
}
Upvotes: 3
Reputation: 19443
change:
public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];
to:
public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];
Upvotes: 2
Reputation: 6890
public CubeStruct cubeArray[,] = new CubeStruct[gridX, gridY];
should be:
public CubeStruct[,] cubeArray = new CubeStruct[gridX, gridY];
Upvotes: 5
Reputation: 726629
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];
Upvotes: 5