This is the problem line:
livro = (char)Console.Read();
The problem is that Console.Read()
only takes one character. But when you type x
and press enter, there are two characters in the buffer, x
and \n
(newline). So when the next Console.Read()
happens, it immediately returns \n
, which is also invalid according to your switch
, and you loop around again.
If you were to enter xxxx
, you would see it loop around once for each x
, until the input buffer is empty again.
Try this instead:
livro = Console.ReadLine().FirstOrDefault();
Here you read an entire line of input (excluding the \n
), and take the first character (or \0
if the user just presses enter).