[英]This member is defined more than once error with variable in if statement
第一个按钮2和1在第一个和第二个if语句中得到此错误。 我如何让他们工作? 提前致谢。
private void button1_Click(object sender, EventArgs e)
{
if (button2 == true)
{
richTextBox1.AppendText(String.Format("Please continue with the midpoint.\n"));
}
else if(button2 == false)
{
richTextBox1.AppendText(String.Format("Type the first set of coordinates in.\n"));
bool button1 = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (button1 == true)
{
richTextBox1.AppendText(String.Format("Please continue with the distance.\n"));
}
else if(button1== false)
{
richTextBox1.AppendText(String.Format("Type the first set of coordinates in.\n"));
bool button2 = true;
}
}
}
}
bool button1 = true;
我假设您已经在查看样本的某处定义了bool值,在这种情况下,您无需再次指定类型:
button1 = true
您需要在类级别上定义这些成员,因为private
成员可能是private
成员,并且需要给他们一个不同的名称/标识符,因为button1
和button2
很可能是您的button
控件名称。
public class someclass
{
private bool mbutton2 = false;
private bool mbutton1 = false;
private void button1_Click(object sender, EventArgs e)
{
if (mbutton2)
{
richTextBox1.AppendText(String.Format
("Please continue with the midpoint.\n"));
}
else
{
richTextBox1.AppendText(String.Format
("Type the first set of coordinates in.\n"));
mbutton1 = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (mbutton1)
{
richTextBox1.AppendText(String.Format
("Please continue with the distance.\n"));
}
else
{
richTextBox1.AppendText(String.Format
("Type the first set of coordinates in.\n"));
mbutton2 = true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.