Microsoft Visual Studio Express无法正确处理}

问题描述:

所以,我是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

编译器在发生错误时我没有,对不起。 –

问题原因:

你的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

很高兴能帮到您 –

所有分号ifelse后需要删除:

if (PSW2 == "MyPassword") ; 

     if (PSW2 == "MyPassword") ; 

    else;