How would I dynamically add multiple labels to a panel whos values are created from a range. I have created the range and added the value to a label and inputted the label to a panel via a foreach loop but the problem is that I am only able to output one.
var range = Enumerable.Range(1, 90);
foreach(int i in range)
{
string num = i.ToString();
var vartable = new Dictionary<string, Label>();
vartable[num] = new Label();
vartable[num].Text = num;
panel1.Controls.Add(vartable[num]);
}
Your problem is that you’re creating a new dictionary for each iteration, which I don’t think is your wanted behavior. Change your code to: