[Solved] How do I prevent from writing a number that is already written?


var number = new int[10];
for (int i = 0; i < number.Length; i++)
{
    Console.Write("Write a number : ");
    int x = int.Parse(Console.ReadLine());
    if (number.Contains(x))
    {
        Console.WriteLine("This number already exists");
        i--; // retry for this index
    }
    else
    {
        number[i] = x;
    }
}

Try something like this if you do not want to use a HashSet.

4

solved How do I prevent from writing a number that is already written?