C# hangman error

0 Jon Gresh · October 2, 2015
Hello,
I am getting an error message on the C# hangman program

if (word.Contains(letter))
            {
                char[] letters = word.ToCharArray();
                for (int i = 0; i < letters.Length; i++)
                {
                    if (letters == letter)
                        labels.Text = letter.ToString(); // <-------------------- this creates an out of range error 
                }
                foreach (Label l in labels)
                if (l.Text == "_") return;
                MessageBox.Show("You have won", "Congrats");
                ResetGame();
            }

Post a Reply

Replies

Oldest  Newest  Rating
0 ariel bitan · October 4, 2015
What is the error?
0 Jon Gresh · October 8, 2015
its an out of range error

it points to this line

labels.Text = letter.ToString();
  • 1

C#

107,262 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators