Creating Array of Buttons that already exist
Hi guys, I have 48 buttons on my form, the problem is; how can I make it as one. I mean, how can I create an array of buttons just like in VB 6.0
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

AlanRank #669 · 3.6K reputationPosted Nov 5, 2008, 11:13 PM EST
In .NET you have to create the array manually.
This is tedious unless your buttons have similar names such as button1, button2, .... , button48 and they're all in the same container such as the form itself.
In that case you can do (.NET 2.0 or later):
Button[] buttons = new Button[48];
for(int i = 0; i < 48; i++)
{
buttons[i] = (Button)this.Controls["button" + (i + 1).ToString()];
}