Trying to find out the elements of ArrayList by using non-generic collection in C#
Hello There, I was trying to find out the all elements of an ArrayList in C# by clicking on a button in the windows form application but it prints only the first element. used +1 too but the result is still the same. I want all the elements to be printed in textbox 2 (not at the same time but clicking on the button5 like first time click it prints a, 2nd time click it prints b, and so on... and we don't know how many elements will user enter in the ArrayList) which are entered in the ArrayList. I tried the below code: ArrayList ar = new ArrayList(); private void button1_Click(object sender, EventArgs e) { ar.Add(textBox1.Text); textBox1.Clear(); textBox1.Focus(); } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); foreach (object ob in ar) { listBox1.Items.Add(ob); } } private void button3_Click(object sender, EventArgs e) { ar.Remove(textBox1.Text); } private void button4_Click(object sender, EventArgs e) { textBox2.Text = ar[0].ToString(); label1.Text = "That's first array"; } private void button5_Click(object sender, EventArgs e) { textBox2.Text = ar[ar.IndexOf(0) + 1].ToString(); } Please check the button 5 code and let me know where I am doing mistakes while making the code on button 5.