2016-10-04 53 views
-1

所以,我是C#的新手,我在創建一個簡單的密碼錶單方面很麻煩。這是代碼的密碼部分Microsoft Visual Studio Express無法正確處理}

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Diagnostics; 
using System.Windows.Forms; 

namespace WindowsFormsApplication4 { 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void btnStrings_Click(object sender, EventArgs e) 
     { 
      string PSW2; 
      PSW2 = TextBox2.Text; 
      if (PSW2 == "MyPassword") ; 
      { 
       if (PSW2 == "MyPassword") ; 
       { 
        MessageBox.Show("Correct!"); 
        Process.Start("http://www.fanime.xyz/"); 
        Environment.Exit(0); 
        Application.Exit(); 
       } 
      } 
      else; 
      { 
       MessageBox.Show("Incorrect!"); 
      } 
     } 

     private void label2_Click(object sender, EventArgs e) 
     { 

     } 

     private void TextBox2_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) 
     { 

     } 
    } 
} 

然而,當我嘗試編譯此它告訴我,}預計否則我如果邏輯門的上方。現在,如果您還沒有注意到,其他上面的符號是左邊的支架}。是否有我的代碼或我的電腦有問題,任何答案將是偉大,謝謝!

+8

這不是C++ ... – Mat

+5

你有很多錯誤放置的';'。它們不是你在線條尾隨處亂濺的東西。 – Mat

+0

編譯器在發生錯誤時我沒有,對不起。 –

回答

1

問題原因:

你的if/else語句語法不正確。您需要刪除;ifelse

解決方案:

更改此:

if (PSW2 == "MyPassword") ; 
{ 
    if (PSW2 == "MyPassword") ; 
    { 
     MessageBox.Show("Correct!"); 
     Process.Start("http://www.fanime.xyz/"); 
     Environment.Exit(0); 
     Application.Exit(); 
    } 
} 
else; 
{ 
    MessageBox.Show("Incorrect!"); 
} 

要這樣:

if (PSW2 == "MyPassword") 
{ 
    if (PSW2 == "MyPassword") 
    { 
     MessageBox.Show("Correct!"); 
     Process.Start("http://www.fanime.xyz/"); 
     Environment.Exit(0); 
     Application.Exit(); 
    } 
} 
else 
{ 
    MessageBox.Show("Incorrect!"); 
} 
+0

並在'if()'之後。 –

+0

謝謝!我沒有看到我花了幾周的時間試圖弄清楚,就是這樣! –

+0

很高興能幫到您 –

0

所有分號ifelse後需要刪除:

if (PSW2 == "MyPassword") ; 

     if (PSW2 == "MyPassword") ; 

    else;