Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 508
Gordon Gustafson Avatar asked Sep 02 '09 21:09

Gordon Gustafson


People also ask

How do I check Output of console WriteLine?

WriteLine("Hello World"); Finally, press Ctrl+Alt+O to open the output window. Your text will be printed there.

How do I display the Output window in Visual Studio?

To display the Output window whenever you build a project, in the Options dialog box, on the Projects and Solutions > General page, select Show Output window when build starts.

How do I get the console log in C#?

In C# you can write or print to console using Console. WriteLine() or Console. Write(), basically both methods are used to print output of console.


2 Answers

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.

like image 159
Alfred Myers Avatar answered Oct 11 '22 13:10

Alfred Myers


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

like image 20
Pierre-Alain Vigeant Avatar answered Oct 11 '22 11:10

Pierre-Alain Vigeant