I need to construct an array with a size equal to the number of elements in an enum. The following test code works just fine:
public enum Test
{
A = 0,
B,
C,
D,
E,
F,
G,
H,
I
}
public int testSize = Enum.GetNames(typeof(Test)).Length;
public int [] test = new int[Enum.GetNames(typeof(Test)).Length];
In my MonoBehaviour Start() function, I can see that “testSize” evaluates to 9 and the size of the “test” array is 9. Now, if I simply add an additional element to the enum, like so:
public enum Test
{
A = 0,
B,
C,
D,
E,
F,
G,
H,
I,
J
}
“testSize” correctly evaluates to 10 but the size of the “test” array is still 9. This happens with my actual game code and with the above test code. Am I doing something utterly diabolical? Is this a C# bug?