I want to store a series (six to be precise) of Windows Forms labels in an array. There are six labels, which follow the naming convention orderLabel0, orderLabel1... orderLabel5.
I would like to store the pointers to the orderLabels in an array:
Label[] orderLabels = new Label[6];
for(int index = 0; index < 6; index++)
{
orderLabels[index] = orderLabel + [index]; //Error!
}
The code somehow needs to treat the string as variable name and store them as "labels" rather than string in the orderLabels array. In other words, when orderLabels[0] is accessed, I am actually accessing orderLabel0.
Research here and there have led me to dynamic, Reflection and Dictionary options. However, they all require me to specify the object names (correct me if I am wrong), and I am trying to follow the "Do Not Repeat" yourself rule by not having to specify the object six times.
Please advise, thank you.
ControlspropertyorderLabel0toorderLabel5already exist on your form?string.Format("orderLabel{0}", index).