My question is simply: how can I shorten this code even more?
List<Button> buttonList = new List<Button>();
buttonList.Add(button1);
buttonList.Add(button2);
buttonList.Add(button3);
buttonList.Add(button4);
buttonList.Add(button5);
buttonList.Add(button6);
buttonList.Add(button7);
buttonList.Add(button8);
buttonList.Add(button9);
If you’ve got your buttons stored in some control’s
Controlscollection (say, aFormor aPanel), then you could use:In this case you may have your method, returning an enumerable of buttons, stored within some container control:
and you may use it: