Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect EOF on the console in C#? What does Console.ReadLine() returns upon 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) {
        }
like image 586
ann dro Avatar asked Sep 18 '25 16:09

ann dro


1 Answers

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.

like image 191
Am_I_Helpful Avatar answered Sep 20 '25 08:09

Am_I_Helpful