IF Statement multiple conditions, same statement
Check this for a more clustered way of checking conditions:
private bool IsColumn(string col, params string[] names) => names.Any(n => n == col);
usage:
private void CheckColumn()
{
if(!IsColumn(ColName, "Column A", "Column B", "Column C"))
{
//not A B C column
}
}
Use the &&
(and) operator in combination with the ||
(or) operator in a nested condition as so:
if (columnname != a
&& columnname != b
&& columnname != c
&& (checkbox.checked || columnname != A2))
{
"statement 1"
}
Should do the trick.
if (columnname != a && columnname != b && columnname != c
&& (columnname != A2 || checkbox.checked))
{
"statement 1"
}
I always try to factor out complex boolean expressions into meaningful variables (you could probably think of better names based on what these columns are used for):
bool notColumnsABC = (columnname != a && columnname != b && columnname != c);
bool notColumnA2OrBoxIsChecked = ( columnname != A2 || checkbox.checked );
if ( notColumnsABC
&& notColumnA2OrBoxIsChecked )
{
"statement 1"
}