The value change in the integer array in one index works in one case, and in another it doesn’t, why?

Asked

Viewed 39 times

0

inserir a descrição da imagem aqui

   private void btnRodaLabirinto_Click(object sender, EventArgs e)
    {
        char[,] Lab = new char[10, 10];
        int[,] Lab2 = new int[10, 10];
        int I = 0, J = 0;
        Random NumerosRandomicos = new Random();

        //abaixo, setando labirinto com 0 e 1
        for (I = 0; I < 10; I++)
        {
            for (J = 0; J < 10; J++)
            {
                Lab2[I, J] = NumerosRandomicos.Next(0, 2);
                if (I == 9 && J == 9) Lab2[I, J] = 3;
                if (I == 0 && J == 0) Lab2[I, J] = 3;
            }
        }

        //Printando na Texbox
        for (I = 0; I < 10; I++)
        {
            for (J = 0; J < 10; J++)
            {
                txtLabirinto.Text = txtLabirinto.Text +
                    Convert.ToString(Lab2[I, J]).ToString();
            }
            txtLabirinto.AppendText("\r\n");
        }

    }

I’ve done away with it, like this:

   I = 0;
   J = 0;
   Lab2[I, J] = 3;

But unsuccessfully too, someone can help me?

  • the code works correctly! what is the error? Example running: https://ideone.com/mWYb6K (despite a bad conversion done)

  • What exactly doesn’t work? Just a hint, in C# we use another nomenclature standard, in general variables have names starting by lowercase

  • The 0.0 position that has an if to be set 3, this being random (0 or 1). Already the 9.9 position which has an if to be set 3 too, is working

  • @Braianfreitas I did even an example: https://ideone.com/mWYb6K and what you said to set to 3 happens in both positions, although the code should be improved but, what is to be done happens yes

  • I understand, maybe I’m making a mistake, because I attached a picture to the result question I’m getting

  • @Braianfreitas I circled in a form and ran your code! no problem at all!

  • I understood, but thanks for the solution (I do not know why my winform is not working), here is showing the result of the photo, I went as a console application and it worked, I don’t know, I’ll sit and cry here

  • I solved the problem, the Textbox (the photo I sent) was small, I increased the size and solved

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.