title: Parsing and looping on user Yes/No console input in C#
body: <p>I'm writing a method that I will use in another code so I'm writing it separately first. </p>
  
  <p>The code returns a boolean based on the first char of the input (yes, Yes, y, yeah, No, ...). But when the input is different from Y or N it starts acting up. In eg3 It stays in the loop until The Console.Read encounters a Y or an N or there are no chars left. In the last case, it will ask again for input. </p>
  
  <p>Am I using the Console.Read wrong or is there another error in my code?
  Thanks in advance</p>
  
  <p>EDIT: Is the solution, in the end, an efficient one?</p>
  
  <p>eg1: </p>
  
  <pre><code>Yes or No?
  YeahIthinkso   &lt;--my input
  True
  </code></pre>
  
  <p>eg2:</p>
  
  <pre><code>Yes or No?
  Negative       &lt;--my input
  False
  </code></pre>
  
  <p>eg3:</p>
  
  <pre><code>Yes or No?
  Idontknow      &lt;--my input
  You can only answer with Yes or No
  Yes or No?
  You can only answer with Yes or No
  Yes or No?
  You can only answer with Yes or No
  Yes or No?
  False
  </code></pre>
  
  <p>The Code:</p>
  
  <pre><code>static void Main(string[] args)
          {
              char YN = 'x';
              bool ans = false;
  
              while (YN == 'x')
              {
                  Console.WriteLine("Yes or No?");
                  YN = char.ToUpper(Convert.ToChar(Console.Read()));
  
  
                  switch (YN)
                  {
                      case 'Y':
                          ans = true;
                          break;
  
                      case 'N':
                          ans = false;
                          break;
  
                      default:
                          Console.WriteLine("You can only answer with Yes or No");
                          YN = 'x';
                          break;
                  }
              }
              Console.WriteLine(ans);
  </code></pre>
  
  <p>Alternate solution based on @StuartLC's answer:</p>
  
  <pre><code>bool ans = true, loop = true;
  do
  {
      switch (Console.ReadLine().ToUpper().FirstOrDefault())
      {
          case 'Y':
              ans = true;
              loop = false;
              break;
  
          case 'N':
              ans = false;
              loop = false;
              break;
  
          default:
              Console.WriteLine("You can only answer with Yes or No");
              break;
      }
  } while (loop==true);
  
  Console.WriteLine(ans);
  </code></pre>