For a school project we are creating a C# application where children can learn.
I made a template in the windows form and want to change the placeholder with the choice of the child, so it can become 1x choice, 2x choice, etc.
I gave every label a name that starts with tafel_noemer_
- tafel_noemer_1
, tafel_noemer_2
, etc.
Now I want to select all those labels up to label 10 and change the placeholder text. I tried this.Name.StartsWith("tafel_noemer_")
but can't get it to work with foreach.
Is there a better way to accomplish this?
You can use Linq's where method:
foreach (Label l in this.Controls.OfType<Label>().Where(l => l.Name.StartsWith("tafel_noemer_")))
{
l.Text = "bla bla";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With