I'm working with C# in a web form. I setup an arraylist. I have a button that add user input in a text box to the arraylist. I'm using the += to print out the arraylist to a label. I'm having trouble just printing out the new entry to the exisiting list. Each time I add, it prints out the whole list again. I understand why it's doing that but just can't wrap my fried brain at the moment how to fix the code so it adds a new entry to the list without repeating the whole list.
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList itemList = new ArrayList();
itemList.Add("red");
itemList.Add("blue");
itemList.Add("green");
itemList.Add(TextBox1.Text);
foreach (object item in itemList)
{
Label1.Text += item + "<br />";
}
}