Populate listbox with integer list C#
I am looking to add the items in a foreach loop to my sumList, however on
trying to return the list to my listbox I only get the first calculation?
List<int> integerList = new List<int>();
List<int> sumList = new List<int>();
int b = 8; // Will be 8 for the first multiplication.
for (int a = 0; a < textBox1.Text.Length; a++)
{
integerList.Add(int.Parse(textBox1.Text[a].ToString()));
}
foreach (int item in integerList) // Loop once per input digit.
{
//listBox1.Items.Add(item * b);
sumList.Add(item * b);
--b;
}
listBox1.DataSource = sumList;
I should get as an output in my list box:
545
564
546
45
52
21
1 etc
However I only get one numeric output? From what I can see the problem is
either with:
sumList.Add(item * b);
Not sure if this overwrites the previous loop or the problem is in
displaying my sumList:
listBox1.DataSource = sumList;
No comments:
Post a Comment