lundi 5 décembre 2016

C# Random Letter Generator into 2D array - Problems

I'm having problems creating a random letter generator. Can anyone point me in the right direction?

I'm getting the error... 'Cannot implicitly convert string to int'.

  class Program
    {
        static void Main(string[] args)
        {

            string[,] Grid = new string[5,5];

            string[] randomLetter = new string[26] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };

            for (int i = 0; i < Grid.GetLength(0); i++)
            {

                for (int j = 0; j < Grid.GetLength(1); j++)
                {

                    Random rng = new Random();

                    int nextRandom = rng.Next(0, 26;

                    string actualRandomLetter = randomLetter[nextRandom];

                    Grid[i, j] = Grid[actualRandomLetter,actualRandomLetter];

                }

            }

        }
  }




Aucun commentaire:

Enregistrer un commentaire