I have on form 3 label. I want all these labels to put in an array so that later in the cycle you could do something like this:
(Windows Forms application)
for (int i = 0; i & lt; 3; i ++)
labels [i] .text = "123";
Answer 1, Authority 100%
var labels = new [] {label1, label2, label3};
Answer 2, Authority 50%
list & lt; Control & GT; List_Labels = New List & lt; Control & GT; ();
list_labels.add (label1);
list_labels.add (label2);
list_labels.add (label3);
For (int i = 0; i & lt; list_labels.count; i ++)
{
List_Labels [i] .text = "123";
}
Answer 3, Authority 50%
label [] labels = new label [3];
for (int i = 0; i & lt; 3; i ++)
{
labels [i] = new label ();
labels [i] .text = i.Tostring ();
this.controls.add (labels [i]);
}
Answer 4
And why do you need an array?
You can do the way as in this answer:
https://stackoverflow.com/questions/4630391/get-All -Controls-of-A-Specific-Type
Create a method that will all pull.
Well, if you still need an array, you can almost also put them in the collection.