C# Question

Can i expand conditions to if in c#

I want to expand condition if checkbox is checked is it possible?

string Condition= "A==B"
if (chechbox1.Checked==true)
{
Condition+="&& B==C";
}
if (chechbox2.Checked==true)
{
Condition+="&& C==D";
}
if (Condition)
{
//do something
}

Answer

use boolean logic:

bool Condition = A == B;  
if (chechbox1.Checked)  
{  
    Condition &= B == C;  
}  
if (chechbox2.Checked)  
{  
    Condition &= C == D;  
}  

if (Condition)  
{  
    //do something  
}  
Comments