How to detect EOF on the console in C#? What does Console.ReadLine() returns upon EOF?

浪子不回头ぞ 提交于 2019-12-12 02:53:11

问题


I would like to read lines from console until EOF. I came up with this solution but I don't know if it is correct one.

        String line;
        while ((line = Console.ReadLine()) != null) {
        }

回答1:


Console.ReadLine Method () returns :

The next line of characters from the input stream, or null if no more lines are available.

Question : I came up with this solution but I don't know if it is correct one!

Answer : Yes, your code is correct.

Also, please go through the added link in the answer to know more about its uses.



来源:https://stackoverflow.com/questions/36526669/how-to-detect-eof-on-the-console-in-c-what-does-console-readline-returns-upo

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