グローバル文字列変数「word」があります。
string word = "";
List<Label> labels = new List<Label>();
int amount = 0;
その単語は、テキスト ドキュメント (改行区切り) を解析することによって、次の 2 つの関数で定義/割り当てられます。
void MakeLabels()
{
word = GetRandomWord();
char[] chars = word.ToCharArray();
...
}
string GetRandomWord()
{
System.IO.StreamReader myFile = new System.IO.StreamReader(...);
string myString = myFile.ReadToEnd();
string[] words = myString.Split('\n');
Random ran = new Random();
return words[ran.Next(0, words.Length - 1)];
}
最後に、テキストボックスの内容を「単語」変数に対して検証するイベントです。
private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text == word)
{
MessageBox.Show(...);
}
else
{
MessageBox.Show(...);
textBox2.Text = "";
textBox1.Focus();
Reset();
}
私が抱えている問題は、textBox2 が「word」に相当する場合でも、else ステートメントに関連する MessageBox を受け取っていることです。「\ n」を運ぶ「単語」変数に関係していると思います。つまり、textBox2.Text = apple および word = apple\n であるため、2 つの変数は同等ではありません。助言がありますか?