R
R
Rebekah2018-01-03 19:48:39
C++ / C#
Rebekah, 2018-01-03 19:48:39

How to remove Form element from List?

There is this code:

public class Randoms
    {
        public static Random rnd = new Random();
        public void GoNext()
        {
            List<Form> LF = new List<Form>();
            LF.Add(new Form1());
            LF.Add(new Form2());
            LF.Add(new Form3());

            var index = rnd.Next(LF.Count);
            if (LF.Count == 0)
            {
                Results RS = new Results();
                RS.Show();
            }
            else
            {
                LF[index].Show();
                LF.RemoveAt(index);
            }
        }
    }

The main form has a button, like all other forms, it calls this method. The method, in turn, creates a sheet with forms, selects a random one and displays it on the screen, and as planned, it should remove it from the sheet, but the forms are still repeated. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question