1

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[]' tofloat'

4 Answers 4

3

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};
Sign up to request clarification or add additional context in comments.

2 Comments

but I want to create a array in that 2array index. for eg. Tile[0,0] = array with 2 indexes
You should have new float rather than float float
2

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

Comments

0

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;

Comments

0

Try the following:

float [,] Tile = new float[17,23];
Tile[0,0] = 2;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.