(Console.BufferHeight) I can't see/scroll to see all the console output with Console.WriteLine

后端 未结 5 840
灰色年华
灰色年华 2020-12-20 14:25

When I run this code, the number at the top of the output window is 99701. Why don\'t I get to see all the way through 1? I actually see all the numbers getting outputted, b

相关标签:
5条回答
  • 2020-12-20 14:32

    It is the console not your app.

    As an alternative you can use Debug.WriteLine (System.Diagnostics) and use the Output window in Visual Studio. It has a much bigger buffer (just be sure to run a Debug build).

    0 讨论(0)
  • 2020-12-20 14:41

    From .Net Framework 2.0 and beyond, you can change the buffer height from within your own program with Console.BufferHeight:

    
    Console.BufferHeight = Int16.MaxValue - 1; // ***** Alters the BufferHeight *****
    List<string> myList = new List<string>();
    for (int x = 0; x < 100000; x++) 
        myList.Add(x.ToString()); 
    foreach (string s in myList) { 
        Console.WriteLine(s); 
    }
    

    The maximum height is Int16.MaxValue - 1.

    0 讨论(0)
  • 2020-12-20 14:44

    300 seems to be your default console buffer size. This is a Windows setting and it is not related to your application.

    You can change the console buffer size by creating a shortcut to the executable. Then right click on the shortcut and select Properties. Go in the Options tab and change the buffer size.

    Seem that I didn't check that feature in a long time, but it seem to be modifiable now. See Alfred Myers answer

    0 讨论(0)
  • 2020-12-20 14:51

    You don't get to see anymore than that because the console does not buffer more than 300 rows by default. Use the settings dialog for the console to change this - I believe you can just start a command prompt and change them there, then run your program.

    Alfred has already pointed out how your application can change the buffer height.

    0 讨论(0)
  • 2020-12-20 14:52

    This has nothing to do with C#, but actually the output buffer in the command prompt is only 300 lines long by default. You can change that in the window settings, although maybe this is an opportunity to try implementing a "more" like feature, which breaks out of the loop every time a screenful of data is output. Then when you press a key, it outputs another screenful, etc.

    0 讨论(0)
提交回复
热议问题