可能重复:
在 C# 中随机化一个 List<T>
我想制作一个程序,随机问用户 5 个问题而不重复问题,如果问题是正确的,如果错误则继续下一个问题,直到他给出正确的答案,这是我编写的代码,但还是有一些问题,比如有重复,当用户输入错误的答案时,它只会停止一次,然后程序就关闭了!现在我怎样才能防止重复相同的问题,如果他输入错误的值不要继续下一个问题或程序关闭?
static void Main()
{
next:
Random question = new Random();
int x = question.Next(5);
string[] array = new string[5];
array[0] = "-What is the capital of France";
array[1] = "-What is the capital of Spain";
array[2] = "-What is the captial of Russia";
array[3] = "-What is the capital of Ukraine";
array[4] = "-What is the capital of Egypt";
Console.WriteLine(array[x]);
string[] answer = new string[5];
answer[0] = "Paris";
answer[1] = "Madrid";
answer[2] = "Moscow";
answer[3] = "Kiev";
answer[4] = "Cairo";
string a = Console.ReadLine();
if (a == answer[x])
{
Console.WriteLine("It's True \n*Next Question is:");
goto next;
}
else
Console.WriteLine("It's False \n*Please Try Again.");
Console.ReadLine();
}