I have a seemingly basic problem with C# arrays. I am a beginner, but this is a really basic problem and it has had me in knots for more than half an hour now. I am using C# 2010 Express.
This code:-
string[] motionCam = new string[8];
motionCam[1] = "Stop";
Reports the error:
Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
Even basic array examples I copy and paste off of education web sites report this same error and I have no clue why.
While the code you pasted is valid, your problem is something else.
Maybe you declared it in the class level.
motionCam[1] = "Stop";
is an assignment not a declaration, this why the compiler shouts.
See this question of someone who had that the same problem.
Bottom line is You can't have non-declaration statements at the class level.