views:

449

answers:

5

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?

+10  A: 

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

Pierre-Alain Vigeant
It can be changed through Console.BufferHeight up to Int16.MaxValue - 1
Alfred Myers
+1  A: 

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.

Michael Madsen
Yes it is. It can be changed through Console.BufferHeight up to Int16.MaxValue - 1
Alfred Myers
I stand corrected. I'll edit accordingly.
Michael Madsen
+1  A: 

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.

Carson Myers
It can be changed through Console.BufferHeight up to Int16.MaxValue - 1
Alfred Myers
+1  A: 

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

Austin Salonen
You can change the console's settings. It can be changed through Console.BufferHeight up to Int16.MaxValue - 1
Alfred Myers
+5  A: 

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.

Alfred Myers
Hmm, indeed you can? Good to know. Still not enough for 100000 items though. :)
Botz3000
That gets me to 67235, but more importantly it explains the problem :D
CrazyJugglerDrummer