private void button1_Click(object sender, EventArgs e)
{
string choice1 = "", choice2 = "";
bool flag = false;
if (radioButton1.Checked) choice1 = "上网";
else if (radioButton2.Checked) choice1 = "打牌";
else if (radioButton3.Checked) choice1 = "跳舞";
if (checkBox1.Checked) { choice2 = "&允许带家属"; flag = true; }
else { choice2 = "&不允许带家属"; flag = true; }
if (choice1 == "") textBox1.Text = "你尚未选择项目";
else textBox1.Text = choice1;
if (!flag) textBox1.Text = textBox1.Text + "你尚未选择是否带家属";
else textBox1 .Text =textBox1 .Text +choice2;
}
if(!flag) 就相当于 if(flag==0)
对应你这里面bool型相当于 if(flag==false)
flag为false才执行下面的语句
因为你这里是检查家属,检查后都会变为true,也就是说到后面只有未检查的情况才是flag==false,才会显示你尚未选择是否带家属
bool要么为true,要么为false,!号就是取反,把true变成false,把false变成true
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!