Microsoft Visual Studio Express无法正确处理}
本文关键字:正确处理 Express Visual Studio Microsoft | 更新日期: 2023-09-27 18:11:20
所以,我是c#的新手,我正在创建一个简单的密码表单。这是密码部分
的代码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)
{
}
}
}
然而,当我试图编译这个时,它告诉我}
预期高于if逻辑门的else。现在,如果您还没有注意到,else 上面的符号是左括号}
。是否有问题与我的代码或我的电脑,任何答案将是伟大,谢谢!
问题原因:
if/else语句语法不正确。在if
和else
之后需要移除;
解决方案:
改变:
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!");
}
去掉if
和else
后面的分号:
if (PSW2 == "MyPassword") ;
if (PSW2 == "MyPassword") ;
else;