namespace DatenfeldDynamisch
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private readonly Random r = new();
        private int[] a = new int[4];

        private void Form1_Activated(object sender, EventArgs e)
        {
            LstFeld.Items.Clear();
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = r.Next(20, 31);
                LstFeld.Items.Add(a[i]);
            }
        }

        private void CmdAnzeigen_Click(object sender, EventArgs e)
        {
            int laenge_alt = a.Length;
            Array.Resize(ref a, (int)NumGroesse.Value);

            LstFeld.Items.Clear();
            for (int i = 0; i < a.Length; i++)
            {
                if (i >= laenge_alt)
                    a[i] = r.Next(20, 31);
                LstFeld.Items.Add(a[i]);
            }
        }
    }
}
