如果选中复选框,我想扩展条件吗?
string Condition= "A==B"
if (chechbox1.Checked==true)
{
Condition+="&& B==C";
}
if (chechbox2.Checked==true)
{
Condition+="&& C==D";
}
if (Condition)
{
//do something
}
答案 0 :(得分:2)
使用布尔逻辑:
bool Condition = A == B;
if (chechbox1.Checked)
{
Condition &= B == C;
}
if (chechbox2.Checked)
{
Condition &= C == D;
}
if (Condition)
{
//do something
}
答案 1 :(得分:1)
不使用字符串,但没有理由不能直接执行此操作:
bool Condition = (A == B);
if (chechbox1.Checked)
{
Condition = Condition && (B == C);
}
if (chechbox2.Checked)
{
Condition = Condition && (C == D);
}
if (Condition)
{
//do something
}