(Console.BufferHeight)我无法使用 Console.WriteLine 查看/滚动查看所有控制台输出

发布于 2024-08-03 21:04:13 字数 772 浏览 7 评论 0原文

当我运行此代码时,输​​出窗口顶部的数字是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

驱逐舰岛风号 2024-08-10 21:04:13

从 .Net Framework 2.0 及更高版本开始,您可以使用 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); 
}

最大高度为 Int16.MaxValue - 1。

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.

口干舌燥 2024-08-10 21:04:13

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

东风软 2024-08-10 21:04:13

这是控制台而不是您的应用程序。

作为替代方案,您可以使用 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).

生生不灭 2024-08-10 21:04:13

这与 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.

芸娘子的小脾气 2024-08-10 21:04:13

您看不到更多的内容,因为默认情况下控制台不会缓冲超过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文