I am making a program which needs to add the value of all numericUpDowns, and display it on the label.
numericUpDowns are created programatically and added to ArrayList.
ArrayList numericUpDownMy = new ArrayList();
numericUpDownMy.Add(new NumericUpDown());
System.Drawing.Point h = new System.Drawing.Point(120, 275+ i * 19);
(numericUpDownMy[i] as NumericUpDown).Location = h;
(numericUpDownMy[i] as NumericUpDown).Size = new System.Drawing.Size(50, 20);
this.Controls.Add(numericUpDownMy[i] as NumericUpDown);
int total = (((int)numericUpDown[0]) + ((int)numericUpDown[1]) + ((int)numericUpDown[2]) + ((int)numericUpDown[3]));
labelScore.Text = total.ToString();
Obviously this doesn’t work as I don’t get the actual value of NumericUpDown. Any advice would be appreciated.
change this line :
and besides that don’t use
ArrayList, useList<NumericUpDown>, to get rid of all that casting or add to collection at the end. I would wrote that code in this way :