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

霸气de小男生 提交于 2019-11-29 13:18:13

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.

Pierre-Alain Vigeant

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

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).

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!