Lets say I have this loop and I put the data in an ArrayList:
int Num1 = Int32.Parse(textBox1.Text);
int Num2 = Int32.Parse(textBox2.Text);
ArrayList ItemList = new ArrayList();
while (Num1 <= Num2)
{
ItemList.Add(Num1);
Num1++;
}
And I have another loop to read my Arraylist:
foreach (int item in ItemList)
{
listBox1.Items.Add("Number " + item.ToString() + ",");
}
Which gives this result:
Number 1,
Number 2,
Number 3,
Number 4,
I need to remove the last comma in the last item and get this result:
Number 1,
Number 2,
Number 3,
Number 4
I've tried this:
foreach (int item in ItemList)
{
listBox1.Items.Add("Number " + item.ToString().Trim(',') + ",");
}
But it doesn't work. Can someone please tell me what I did wrong, and how I can fix it?