So, I’m having this array that adds elements one by one pressing a button, and it adds elements with this:
arreglo.Add(textBox1.Text.ToString());
I just want to limit the amount of elements it can add to the array, to 10. It can have up to ten elements, no more. How do i do that?
If it helps, these are parts of my code I think it can help:
ArrayList arreglo;
public Form1()
{
InitializeComponent();
arreglo = new ArrayList();
}
and
private void button5_Click(object sender, EventArgs e)
{
//Agregar
arreglo.Add(textBox1.Text.ToString());
/*if (arreglo.Count > 10)
{
listBox1.Items.Add("No more than ten elements");
}*/
this.textBox1.Clear();
this.textBox1.Focus();
}
And btw, i also need to do some calculations with that array, but i already have that covered.
You can simply solve this as: