Reputation: 345
I am new in c#, I am trying to create a simple array in a 2D array, Em trying following code but getting error,
float [,] Tile = new float[17,23];
Tile[0,0] = new float[2] {1,2};
em getting error: Cannot implicitly convert type float[]' to
float'
Upvotes: 1
Views: 9477
Reputation: 9226
Try the following:
float [,] Tile = new float[17,23];
Tile[0,0] = 2;
Upvotes: 0
Reputation: 6184
Tile[0,0]
is a single float.
So you should add it like this
float [,] Tile = new float[17,23];
Tile[0,0] = 1;
Tile[0,1] = 2;
Tile[1,1] = 1337;
etc..
Edit From your comment you can do something like this
float [,][] Tile = new float[17, 23][];
Tile [0,0] = new float[] {1,2};
Upvotes: 3
Reputation: 565
Here is right code:
float[,][] Tile = new float[17, 23][];
Tile[0, 0] = new float[2] { 1, 2 };
More information on C# arrays at http://msdn.microsoft.com/en-us/library/2s05feca.aspx
Upvotes: 2
Reputation: 2293
I am not sure what you are trying to achieve here, but your code should be like:
float[,] Tile = new float[17, 23];
Tile[0, 0] = 1.0f;
Tile[0, 1] = 2.0f;
Upvotes: 0