The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
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.
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?
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.
If you want a variable size container, look at List<T>.
This isn't true. float [,,] is a valid type that can be null, and can be assigned, or used as a parameter. I am confused by the OP, because what he has there is perfectly acceptable C#. I even pasted it into VS2008 and it compiles. Do you have another error in say, the line after what you pasted?
If you want a variable size container, look at List<T>.
This isn't true. float [,,] is a valid type that can be null, and can be assigned, or used as a parameter. I am confused by the OP, because what he has there is perfectly acceptable C#. I even pasted it into VS2008 and it compiles. Do you have another error in say, the line after what you pasted?
Based on the error, I would guess the OP is actually using the second line outside of any method, something like this:
public class MyClass
{
float[, ,] x = null;
x = new float[4,8,8];
public void MyMethod()
{
Stuff
}
}
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.
If you want a variable size container, look at List<T>.
This isn't true. float [,,] is a valid type that can be null, and can be assigned, or used as a parameter. I am confused by the OP, because what he has there is perfectly acceptable C#. I even pasted it into VS2008 and it compiles. Do you have another error in say, the line after what you pasted?
Based on the error, I would guess the OP is actually using the second line outside of any method, something like this:
public class MyClass
{
float[, ,] x = null;
x = new float[4,8,8];
public void MyMethod()
{
Stuff
}
}
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.
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!