Click here to Skip to main content
15,889,861 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:
C#
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:
C#
public Game(int[,] Grass, int[,] Rocks, int[,] positions, int level)


I have used the following line to try to call the method:
C#
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.

Stephen.
Posted
Updated 16-Jan-14 2:00am
v2

You need to declare myLevel as
C#
int[,][,] myLevel
 
Share this answer
 
Comments
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;
<pre>
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:
C#
int[,] [,] myLevel ={ { Green, Brown, positions1 }, { Green2, Brown2, positions2 } };
 
Share this answer
 
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.

Stephen.
 
Share this answer
 

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