Jonny123
Member
- Joined
- Oct 2, 2015
- Messages
- 13
- Programming Experience
- Beginner
Hello,
I am getting an error message on the C# hangman program that i'm trying to recreate from a YouTube video at:
https://www.youtube.com/watch?v=E8XQ9x-7yYk
the program seems to run fairly well, but runs into an error once in a while. I'm not sure what code is needed to display the problem that I am having. Below is the section in which the error message shows.
I am getting an error message on the C# hangman program that i'm trying to recreate from a YouTube video at:
https://www.youtube.com/watch?v=E8XQ9x-7yYk
the program seems to run fairly well, but runs into an error once in a while. I'm not sure what code is needed to display the problem that I am having. Below is the section in which the error message shows.
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(); }