How can I update the current line in a C# Windows Console App?

前端 未结 17 1029
南旧
南旧 2020-11-22 14:43

When building a Windows Console App in C#, is it possible to write to the console without having to extend a current line or go to a new line? For example, if I want to sho

17条回答
  •  粉色の甜心
    2020-11-22 15:08

    From the Console docs in MSDN:

    You can solve this problem by setting the TextWriter.NewLine property of the Out or Error property to another line termination string. For example, the C# statement, Console.Error.NewLine = "\r\n\r\n";, sets the line termination string for the standard error output stream to two carriage return and line feed sequences. Then you can explicitly call the WriteLine method of the error output stream object, as in the C# statement, Console.Error.WriteLine();

    So - I did this:

    Console.Out.Newline = String.Empty;
    

    Then I am able to control the output myself;

    Console.WriteLine("Starting item 1:");
        Item1();
    Console.WriteLine("OK.\nStarting Item2:");
    

    Another way of getting there.

提交回复
热议问题