samedi 5 décembre 2020

How Do you Randomly Select a line in a textfile, display it on a label and remove from list?

I want to select a line randomly in my text file nd display it on a label and remove it so it cant be seen again unless the text file has ran out of lines, I know how to read in but not display a random line and remove it...

For reference I am creating a game and on my splash I am displaying tips and removing each time its been displayed but ill do a count on each time its removed and clear the list if there is nothing left...

                try
                {
                  
                    using (StreamReader sr = new StreamReader("MarioBrosFacts.txt"))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            MarioBrosClass.MarioBrosFact.Add(line);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("File path cannot be found");
                }
                break;



Aucun commentaire:

Enregistrer un commentaire