float[, ,] x = null;
x = new float[4,8,8]; (all the error are on this line)
error CS1519: Invalid token '=' in class, struct, or interface member declaration
error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
error CS1519: Invalid token ';' in class, struct, or interface member declaration
If I declare it this way
float[, ,] x = new float[4,8,8]; I works fine but from what I've found via google if you want to declare array size via a variable(which is what I want to do) you have to do it the way that's giving me the errors.
Any ideas from you programming gurus out there?
Posts
First off, there's actually a programming thread in the tech subforum, so you're best off posting the question there.
Second, I don't see why you would have to do that. float[, ,] x = new float[i,j,k]; should work fine. I'm curious to see where you got the advice.
http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx
If you want a variable size container, look at List<T>.
Based on the error, I would guess the OP is actually using the second line outside of any method, something like this:
The direct assignment works because that's the default value you're assigning it. You can't do an assignment for an already declared variable as part of a class definition.
That's it!