vendredi 10 mars 2017

How to make if statement for multiple elements? C#

I am using VS2017 and C# on Windows Forms.

I'm creating a little tool and I need some assistance.

I have 10 text boxes, names textGame1, textGame2, textGame3, etc etc

Image

I want to create code, in which if the any of the text boxes are empty, then it will replace the textbox text to "EMPTY".

I could easily do

if (string.IsNullOrWhiteSpace(textGame1.Text))
            {
                textGame1.Text = "EMPTY";
            }

However I would have to create 10 of those for each text box.

Is there a simpler way, than to create 10 of these IF statements?

Aucun commentaire:

Enregistrer un commentaire