如何在C#中的控制台上检测EOF? Console.ReadLine()在EOF上返回什么? [英] How to detect EOF on the console in C#? What does Console.ReadLine() returns upon EOF?

查看:176
本文介绍了如何在C#中的控制台上检测EOF? Console.ReadLine()在EOF上返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从控制台读取行,直到EOF。我想出了这个解决方案,但我不知道它是否正确。

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) {
        }


推荐答案

Console.ReadLine方法()返回:


输入流中的下一行字符,

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.

这篇关于如何在C#中的控制台上检测EOF? Console.ReadLine()在EOF上返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆