(一切都在C#中製作) loggedIn
變量在MainWindow
類中不會變爲true
? label
會改變,但變量不會。 我該如何解決這個問題?謝謝你幫助我!C#變量不會改變?
MainWindow game = new MainWindow();
if(!game.loggedIn)
{
if (tbxUsername.Text != "" && tbxPassword.Text != "")
{
if(System.IO.File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "Passwords\\" + tbxUsername.Text + ".txt"))
{
if(System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "Passwords\\" + tbxUsername.Text + ".txt") == tbxPassword.Text)
{
game.loggedIn = true;
game.username = tbxUsername.Text;
game.password = tbxPassword.Text;
lblMessage.Content = "U bent ingelogd als " + game.username + "!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
else
{
lblMessage.Content = "U heeft een verkeerd password ingegeven!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "Deze username bestaat niet!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "U heeft geen password/username ingegeven!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "U bent al ingelogd!";
}
}
你是什麼意思了新
MainWindow
每次初始化通過*不會改變*?你有沒有嘗試調試代碼?你有錯誤嗎? –我希望這不是生產代碼。可怕的方式來應對密碼... – jeroenh
調試代碼。我們不知道你的輸入是什麼。逐行瀏覽每一行,並檢查實際值與您的期望值。 – Jonesopolis