I am writing a windows forms application that has 4 check boxes that can be checked at the same time. I want to check to see what boxes are checked and do specific logic based on which boxes are checked. The issue being that if I end up trying to write code to check each possible combination of the check boxes I would have to write a long list of if else statements, and that is without checking for if there is only one checked. Is there any more elegant way to check whether or not multiple check boxes are checked? or am I stuck using if-else logic?
//This is the type of code I am trying to avoid
//check all the conditions
//check1 is a check to add keys
//check2 is to create docs
//check3 is to create keys
//check4 is to reorder keys
//createKeys() creates keywords
//createDocs() creates documents
//addKeys() adds keywords
//reorderKeys reorders the keywords
if(check1 && check2 && check3 && check4){
createKeys();
createDocs();
addKeys();
reorderKeys();
}
else if(check1 && check2 && check3){
createKeys();
createDocs();
addKeys();
}
else if(check1 && check2 && check4){
createDocs();
addKeys();
reorderKeys();
}
else if(check1 && check2){
createDocs();
addKeys();
}
else if(check1){
addKeys();
}
else if(check2 && check3 && check4){
createKeys();
createDocs();
reorderKeys();
}
else if(check2 && check4){
createDocs();
reorderKeys();
}
else if(check2){
createDocs();
}
else if(check3 && check4){
createKeys();
reorderKeys();
}
else if(check3){
createKeys();
}
else if(check4){
reorderKeys();
}
Code update to be more specific