I have code that is very dirty with if - else if it checks. The number of branching and nested branches is quite large (more than 20 if-else if and nested). This makes my code more difficult to read and will probably be a performance whistle. My application checks the many conditions that it receives from the user, and therefore the application must constantly check various situations, for example:
If the text of the text field is not 0, continue with the following ...
if ((StartInt != 0) && (EndInt != 0)) {
Then it checks if the user selects dates:
if ((datePickerStart.SelectedDate == null) || (datePickerEnd.SelectedDate == null)) { MessageBox.Show("Please Choose Dates"); }
Here, if datepickers are not null, it continues with code ...
else if ((datePickerStart.SelectedDate != null) && (datePickerEnd.SelectedDate != null)) { // CONDITIONS FOR SAME STARTING DAY AND ENDING DAY. if (datePickerStart.SelectedDate == datePickerEnd.SelectedDate) { if (index1 == index2) { if (StartInt == EndInt) { if (radioButton1.IsChecked == true) { printTime3(); } else { printTime(); } }
This is only a small part of the checks. Some of them are functional, and some of them relate to input verification materials.
Is there a way to make it more readable and less workable?
source share