Home c# line record in a file from the console

line record in a file from the console

Author

Date

Category

There is a code:

do {
    Using (Streamwriter File = New Streamwriter ("NEWS.TXT", TRUE))
    {
      file.writeline ($ "{Console.ReadLine ()}");
    }
  } While (Console.ReadLine ()! = "");

You need to implement the entry in news.txt one line from the console before the user will skip the string by pressing ENTER. This method writes for some reason not all lines, namely, misses each second


Answer 1, Authority 100%

Request for reading and waiting for input is performed with any CONSOLE.REDLINE () call. In your case, the problem here:

While (Console.ReadLine ()! = “”);

This entered string will not be recorded.

Code Change Easy:

string newsline;
Using (Streamwriter File = New Streamwriter ("NEWS.TXT", TRUE))
{
  do.
  {
    Newsline = Console.ReadLine ();
    File.Writeline (Newsline);
  }
  While (Newsline! = "");
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions