C# Select random element from List

Are you sure that you want to remove a question and return the rest of the questions?
Should you not only select one? Somthing like this :

public static void main()
{
    var random = new Random();
    var questions = new List<string>{
        "question1",
        "question2",
        "question3"};
    int index = random.Next(questions.Count);
    Console.WriteLine(questions[index]);
}

Leave a Comment