C# why is it skipping my console.readline()?

巧了我就是萌 提交于 2019-11-28 02:24:42

It's because of your Console.Read() call in DisplayResults method. It generally reads just one character. If you press ENTER (which is actually combination of 2 characters - carriage return and line feed) on Console.Read() it only gets carriage return character, and line feed gets to your next console reading method - Console.ReadLine() in GetInput() method. Since line feed character is also a linux ENTER character, Console.ReadLine() reads it as one line.

Try changing the Console.Read() in your DisplayResults method to Console.ReadLine(). That seems to make everything behave as it should.

You said the second time round. Looking at your do-while loop, That would fall through because your variable inString is initialised and not empty.

Btw, usually safer to use

do
{
} while (!String.IsNullOrEmpty(inString));

than to directly compare to an empty string.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!