1

I'm getting the error:

"Ambiguity between 'game.Form1.WallCheckerArray' and 'game.Form1.WallCheckerArray'"

Because I use it twice. Why can't I use the same array name twice with different values? My code is below. The array exists out of cordinates.

my array:

private int[,] WallCheckerArray = new int[28, 4];// <<----- was the problem
        int[,] WallCheckerArray = {
                                      {220,250,13,64},//1
                                      {24,58,24,55},//2
                                      {104,206,22,55},//3
                                      {264,370,22,55},//4
                                      {382,450,22,55},//5
                                      {24,92,74,109},//6
                                      {104,136,74,185},//7
                                      {136,206,114,138},//8
                                      {150,326,74,98},//9
                                      {225,255,98,140},//10
                                      {345,365,74,185},//11
                                      {275,355,114,138},//12
                                      {384,445,74,109},//13
                                      {104,136,200,270},//14
                                      {150,330,240,270},//15
                                      {225,255,270,315},//16
                                      {340,370,200,270},//17
                                      {20,85,285,305},//18
                                      {50,85,305,345},//19
                                      {104,214,285,315},//20
                                      {274,368,285,315},//21
                                      {378,445,285,305},//22
                                      {378,415,305,345},//23
                                      {24,195,365,375},//24
                                      {104,154,335,375},//25
                                      {165,339,335,345},//26
                                      {215,245,335,375},//27
                                      {265,445,365,375},//28
                                      {355,365,335,375}//29
                                  };


int i = 0;
for( i = 0; i < 29; i++)
{
    if (((x >= WallCheckerArray[i, 0] && x <= WallCheckerArray[i, 1]) && (y >= WallCheckerArray[i, 2] && y <= WallCheckerArray[i, 3])))//-----------------------------------}-
         {
            InsideWC();
            System.Console.WriteLine(WallCheckerArray[i, 1]);
         }
}
6
  • 3
    That error doesn't mean you used it twice, but that there are two instances of WallCheckerArray in the same form. Commented Aug 29, 2013 at 18:58
  • 1
    Don't use arrays and for loops like that. Create a proper data model instead. Commented Aug 29, 2013 at 19:00
  • i can't find it any where else in my code exept for this part. Commented Aug 29, 2013 at 19:03
  • 3
    Using Visual Studio? In that piece of your code, right click the name WallCheckerArray and select FindAllReferences. Commented Aug 29, 2013 at 19:12
  • Did you name a control WallCheckerArray? Tip: At least use for( i = 0; i < WallCheckerArray.GetLength(0); i++) to get the highbound for the first index Commented Aug 29, 2013 at 19:13

2 Answers 2

4

A line of code like int[,] WallCheckerArray = something is read by the compiler as "Make a new int[,] named WallCheckerArray. And the problem is, you do that twice in a row; you can't have two different variables with the same name. If you don't give a variable an access modifier, the C# compiler will assume you wanted it to be Private.

To make your code work:

private int[,] WallCheckerArray = new int[28, 4];
        WallCheckerArray = {
                                 /* Your Data */
                           };

FYI: you can actually make your array and fill it with data in the same statement, like so:

private int[,] WallCheckerArray = {
                                      {220,250,13,64},
                                      {24,58,24,55},
                                      {104,206,22,55},
                                      // and so on
                                  };

This way, you don't have to worry about declaring the size of the array, it'll be handled for you.

Sign up to request clarification or add additional context in comments.

Comments

0

Had to delete "private int[,] WallCheckerArray = new int[28, 4];"

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.