There is a code:

do { using (StreamWriter file = new StreamWriter("news.txt", true)) { file.WriteLine($"{ Console.ReadLine()}"); } } while (Console.ReadLine() != ""); 

You need to implement an entry in news.txt one line from the console before the user skips the line by pressing Enter. This method for some reason records not all the lines, namely, it passes each second

    1 answer 1

    A request to read and wait for input is executed during any call to Console.ReadLine() . In your case, the problem is here:

    while (Console.ReadLine ()! = "");

    This entered string will not be written.

    Code change is easy:

     string newsLine; using (StreamWriter file = new StreamWriter("news.txt", true)) { do { newsLine = Console.ReadLine(); file.WriteLine(newsLine); } while (newsLine != ""); } 
    • Another would be to open the flow of the cycle. This is a serious operation. - Alexander Petrov
    • Yes, I even stupid, now I will correct - rdorn
    • This also changes the code behavior! - Pavel Mayorov
    • @PavelMayorov: Yes, but I would say for the better. I can argue that there was no particular idea in opening the file in the loop, “it just happened.” - VladD
    • one
      In the current formulation of the question, the changes are for the better, but in other scenarios the initial opening of the duct inside the cycle allows not to block the file for a long time. - rdorn