jeudi 12 avril 2018

Array out of bounds in for loop

//dice throws to arrays
        int throws = 1;
        int[] oneDice = new int[throws];
        int[,] twoDice = new int[throws,throws];

        Console.WriteLine("Number of throws: ");
        throws = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Trows one dice "+throws+" times: ");
        for (int i = 0; i < throws; i++)
        {
            Random random = new Random();
            oneDice[i] = random.Next(6);
            Console.WriteLine(oneDice[i]);

        }

It says my array oneDice is out of bounds, but i dont get why.. Please help me figuring it out.




Aucun commentaire:

Enregistrer un commentaire