+ 1
Console.In.Peek
Can someone explain this part code in this code please: while (Console.In.Peek() != -1) { Console.Read(); } break; https://code.sololearn.com/cmw5Zx2j7SB5/?ref=app
4 Answers
+ 1
(Console.In.Peek() != -1) checks for the presence of any character in the input console, if there are no characters, then the result will be -1.
But as far as I understand this cycle is inappropriate here.
I'm not good with c#, but I would fix it.
+ 1
Okay, now the last Console.Read() is not needed either, reading the input happens in the loop condition.āŗļø
+ 1
Solo š thanks
+ 1
Okay, now let's go back to the Peek() method to avoid the infinite loop: š
while(Console.In.Peek()!=-1){
ch = (char)Console.Read();
switch(ch){
...
Now you can enter any number of numbers, or enter nothing. š