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

Gor*_*son 11 .net c# 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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Console.Write(s)很好,但是Console.Write(s +"\n")没有.我猜我只能向上滚动这么多新行?

Alf*_*ers 26

从.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); 
}
Run Code Online (Sandbox Code Playgroud)

最大高度为Int16.MaxValue - 1.


Pie*_*ant 11

300似乎是您的默认控制台缓冲区大小.这是Windows设置,与您的应用程序无关.

您可以通过创建可执行文件的快捷方式来更改控制台缓冲区大小.然后右键单击快捷方式并选择"属性".转到"选项"选项卡并更改缓冲区大小.

似乎我很长时间没有检查该功能,但它现在似乎可以修改.见Alfred Myers回答

  • 它可以通过Console.BufferHeight更改为Int16.MaxValue - 1 (3认同)