How could I rewrite this? I'd like to see as many ideas as you can come up with so I can pick one I like. I prefer simple and smart solutions.if (txtName.Text == ) {  txtName.Focus(); } else if (txtSNo.Text == )  {   txtSNo.Focus();  } else if (txtFNo.Text == )  {   txtFNo.Focus();  } else if (txtMNo.Text == )  {   txtMNo.Focus();  } else if (txtEID.Text == )  {   txtEID.Focus();  }
Cleaning up nested if statements
c#
How about using some form of collection, then iterating over it to call the .Text property, and if it's empty, setting focus and breaking the loop?The algorithm would be like this: (pseudo code)foreach (var textfield in textfieldList){    if(textfield.Text == ){        textfield.Focus();        break;    }}I'd use a List as the collection to iterate over.