简体   繁体   English

在C#控制台窗口中打印

[英]Printing in C# console window

I am trying to print 1820 lines in C# console window. 我试图在C#控制台窗口中打印1820行。 However, when the printing is done and I view the console window, I can see only 300 lines. 但是,当打印完成并且我查看控制台窗口时,我只能看到300行。 What is the problem here? 这里有什么问题? When I write to file, I can see 1820 lines! 当我写入文件时,我可以看到1820行! So, I have narrowed down the problem to the OUTPUT console window 所以,我已将问题缩小到OUTPUT控制台窗口

The standard console window in most versions of Windows have a limited buffer of lines they keep - 300 lines sounds like a reasonable buffer. 大多数Windows版本的标准控制台窗口都有有限的缓冲线 - 300行听起来像是一个合理的缓冲区。

You can see (and change) that limit when you open a cmd.exe window and then right-click on the icon in the top left corner and choose Properties from the context menu: 打开cmd.exe窗口然后右键单击左上角的图标并从上下文菜单中选择“ Properties ,可以查看(并更改)该限制:

替代文字

You might be able to increase the size of that buffer to give you more lines - keep in mind that those lines will take up RAM from your system while your console window is open! 您可以增加该缓冲区的大小以提供更多行 - 请记住,当您的控制台窗口打开时,这些行将占用系统中的RAM!

You can use Console.SetBufferSize() to make the console buffer larger: 您可以使用Console.SetBufferSize()使控制台缓冲区更大:

class Program {
    static void Main(string[] args) {
        Console.SetBufferSize(Console.WindowWidth, 2000);
        // etc..
    }
}

-- Small Addition -- - 小额 -

If hoping to get the maximum possible buffer: 如果希望获得最大可能的缓冲区:

 Console.SetBufferSize(Console.WindowWidth, Int16.MaxValue-1);

You're not allowed anything >= Int16.MaxValue 你不允许任何东西> = Int16.MaxValue

Adjust the buffer size for the window: 调整窗口的缓冲区大小:

  • Click the icon in the top-left of the window. 单击窗口左上角的图标。
  • Properties 属性
  • Layout 布局
  • Screen Buffer Size 屏幕缓冲区大小
  • Enter the maximum value for height: 9999 输入高度的最大值:9999

If you need more than this then you need to use a GUI or write to a file and view it in a text editor. 如果您需要更多,则需要使用GUI或写入文件并在文本编辑器中查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM