I am wondering is there a way of shortening my code by creating a concatenation for the name of my buttons. I have tried a few things but didn't work.
I have 10 buttons and named all btnCab1, btnCab2 etc and I want to add them to a list of buttons without using btn.Add(btnCab1)
for every single one of them. This is the example:
List<Button> btn = new List<Button>();
btn.Add(btnCab1);
btn.Add(btnCab2);
btn.Add(btnCab3);
btn.Add(btnCab4);
btn.Add(btnCab5);
btn.Add(btnCab6);
btn.Add(btnCab7);
btn.Add(btnCab8);
btn.Add(btnCab9);
btn.Add(btnCab10);
foreach (CheckingIn c in inCabin)
{
int val = c.CabinNumber;
foreach(Button b in btn)
{
if(val == (btn.IndexOf(b) + 1))
{
b.BackColor = Color.Red;
}
}
}
However, let's also take into consideration that I may have 100 buttons. Thank you in advance!