(Console.BufferHeight)我无法使用 Console.WriteLine 查看/滚动查看所有控制台输出
当我运行此代码时,输出窗口顶部的数字是 99701。为什么我看不到一直到 1 的数字?我实际上看到所有数字都被输出,但在控制台窗口上,我只能滚动到足够高才能看到 99701 (我猜)。我在 Vista Home 上使用 Visual C# Express。 :D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using utilities;
namespace Testing_Project {
class Program {
static void Main(string[] args) {
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);
}
Console.Read();
}
}
}
Console.Write(s) 可以,但 Console.Write( s+"\n") 不行。我猜我只能向上滚动这么多换行符?
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, but on the console window, I can only SCROLL high enough to see 99701 (I'm guessing). I'm using Visual C# express on Vista Home. :D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using utilities;
namespace Testing_Project {
class Program {
static void Main(string[] args) {
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);
}
Console.Read();
}
}
}
Console.Write(s) does fine, but Console.Write( s+"\n") does not. I'm guessing I can only scroll up through so many newlines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从 .Net Framework 2.0 及更高版本开始,您可以使用 Console.BufferHeight:
最大高度为 Int16.MaxValue - 1。
From .Net Framework 2.0 and beyond, you can change the buffer height from within your own program with Console.BufferHeight:
The maximum height is Int16.MaxValue - 1.
300 似乎是您的默认控制台缓冲区大小。这是 Windows 设置,与您的应用程序无关。
您可以通过创建可执行文件的快捷方式来更改控制台缓冲区大小。然后右键单击该快捷方式并选择属性。进入“选项”选项卡并更改缓冲区大小。
似乎我很长时间没有检查该功能,但现在似乎可以修改。请参阅阿尔弗雷德·迈尔斯的回答
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
这是控制台而不是您的应用程序。
作为替代方案,您可以使用 Debug.WriteLine (System.Diagnostics) 并使用 Visual Studio 中的“输出”窗口。它有一个更大的缓冲区(只需确保运行调试版本)。
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).
这与 C# 无关,但实际上命令提示符中的输出缓冲区默认只有 300 行长。您可以在窗口设置中更改它,尽管这也许是尝试实现“更多”类似功能的机会,该功能每次输出一屏数据时都会跳出循环。然后当你按下一个键时,它会输出另一个屏幕,等等。
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.
您看不到更多的内容,因为默认情况下控制台不会缓冲超过 300 行。使用控制台的设置对话框来更改此设置 - 我相信您可以启动命令提示符并在那里更改它们,然后运行您的程序。
Alfred 已经指出了您的应用程序如何更改缓冲区高度。
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.