Question: Sorry if this is similar to an existing question - I did try looking!

Anyhow, I've got a program going as follows:

```
    static void Main(string[] args)
    {
        string temp;

        Console.WriteLine("question");
        temp = Console.ReadLine();

        if (temp == "a")
        {
            Console.WriteLine("Incorrect");
        }
        if (temp == "b")
        {
            Console.WriteLine("Incorrect");
        }
        if (temp == "c")
        {
            Console.WriteLine("Correct");
        }
        else
        {
            Console.WriteLine("Not a valid response");
        }

    }

```

And I'm trying to get it to *ignore invalid responses* until I give a valid response. If for example, I needed to press the key `a`, or `b`, or `c` but I pressed `d`, it would just tell me my answer *isn't a valid option* and wait until I gave a *valid response*.

Answer: 
You can implement (extract) a method:

```
 private static char AnswerTheQuestion(string question, int answers) {
   Console.WriteLine(question);

   // Loop until...
   while (true) {
     // Let's be nice and tolerate leading / trailing spaces
     string answer = Console.ReadLine().Trim();

     if (answer.Length == 1) {
       char result = char.ToLower(answer[0]); // let's ignore case ('A' == 'a' etc.)

       if (result >= 'a' && result <= 'a' + answers)
         return result; // ...user provide an answer in expected format
     }

     // Comment it out if you want just to ignore invalid input 
     Console.WriteLine($"Sorry, provide an answer in [a..{(char)('a' + answers)}] range");
   }
 }

```

Then you can use it:

```
   static void Main(string[] args) { 
     char result = AnswerTheQuestion(string.Join(Environment.NewLine,
           "What is the capital of Russia?",
           "  a. Saint-Petersburg",
           "  b. Moscow",
           "  c. Novgorod"),
       3);

     Console.WriteLine($"{(result == 'b' ? "correct" : "incorrect")}");

     Console.ReadKey(); 
   }

```
```cs
void Main()
{
    string temp;

    Console.WriteLine("question");
    while (true)
    {
        temp = Console.ReadLine();

        if (temp == "a")
            Console.WriteLine("Incorrect"); 
        else if (temp == "b")
            Console.WriteLine("Incorrect");
        else if (temp == "c")
            Console.WriteLine("Correct");
        else if (temp == "exit") // providing a way to exit the loop
            break;
        else { } // ignore input            
    }
}

```