Click here to Skip to main content
15,068,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm probably doing something very obviously wrong here but I'm not sure how to modify my code to correct it. Just wondering if anyone has any advice:

I create the variable:
Array[,] myLevel = { { Green, Brown, positions1 }, { Green2, Brown2, positions2 } };

where each of the elements Green, Brown, positions1, etc. are of the type int[,].

I then want to create an instance of my method Game:
public Game(int[,] Grass, int[,] Rocks, int[,] positions, int level)

I have used the following line to try to call the method:
Game game1 = new Game(myLevel[thislevel, 0], myLevel[thislevel, 1], myLevel[thislevel, 2], thislevel);

I get the error message "Cannot convert from System.Array to int[*,*].

Thanks very much for any advice.

Updated 16-Jan-14 2:00am

You need to declare myLevel as
int[,][,] myLevel
Fredrik Bornander 16-Jan-14 8:09am
That's what I would do.
If he can't change that type then cast the Array parameters;
new Game((int[,])myLevel[thislevel, 0], (int[,])myLevel[thislevel, 1], (int[,])myLevel[thislevel, 2], thislevel); </pre>
myLevel is a multidimensional array of multidimensional int arrays, that is:
int[,] [,] myLevel ={ { Green, Brown, positions1 }, { Green2, Brown2, positions2 } };
Thanks for all of your advice. Tomas your suggestion worked, and thanks for the alternative solution also Fredrick. Also, thanks for clearing up my confusion CPallini. These tips have helped greatly.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900