Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing in C# console window

Tags:

c#

I am trying to print 1820 lines in C# console window. However, when the printing is done and I view the console window, I can see only 300 lines. What is the problem here? When I write to file, I can see 1820 lines! So, I have narrowed down the problem to the OUTPUT console window

like image 678
Programmer Avatar asked Dec 08 '22 00:12

Programmer


2 Answers

The standard console window in most versions of Windows have a limited buffer of lines they keep - 300 lines sounds like a reasonable buffer.

You can see (and change) that limit when you open a cmd.exe window and then right-click on the icon in the top left corner and choose Properties from the context menu:

alt text

You might be able to increase the size of that buffer to give you more lines - keep in mind that those lines will take up RAM from your system while your console window is open!

like image 148
marc_s Avatar answered Feb 09 '23 00:02

marc_s


You can use Console.SetBufferSize() to make the console buffer larger:

class Program {
    static void Main(string[] args) {
        Console.SetBufferSize(Console.WindowWidth, 2000);
        // etc..
    }
}

--Small Addition--

If hoping to get the maximum possible buffer:

 Console.SetBufferSize(Console.WindowWidth, Int16.MaxValue-1);

You're not allowed anything >= Int16.MaxValue

like image 33
Hans Passant Avatar answered Feb 08 '23 23:02

Hans Passant