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

5

11

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?

Acred answered 2/9, 2009 at 21:14 Comment(1)
+1 for your question, because a lot of people got it wrong ;)Reprobative
R
26

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.

Reprobative answered 2/9, 2009 at 21:56 Comment(3)
Hmm, indeed you can? Good to know. Still not enough for 100000 items though. :)Neurosurgery
That gets me to 67235, but more importantly it explains the problem :DAcred
a bit confusing that BufferHeight and BufferWidth are Int32 but only accept Int16 values. :/Ruffina
J
10

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

Juliettejulina answered 2/9, 2009 at 21:16 Comment(1)
It can be changed through Console.BufferHeight up to Int16.MaxValue - 1Reprobative
E
3

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

Eboh answered 2/9, 2009 at 21:36 Comment(1)
You can change the console's settings. It can be changed through Console.BufferHeight up to Int16.MaxValue - 1Reprobative
F
2

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.

Fondness answered 2/9, 2009 at 21:17 Comment(1)
Yes it is. It can be changed through Console.BufferHeight up to Int16.MaxValue - 1Reprobative
S
2

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.

Sibert answered 2/9, 2009 at 21:18 Comment(1)
It can be changed through Console.BufferHeight up to Int16.MaxValue - 1Reprobative

© 2022 - 2024 — McMap. All rights reserved.