简体   繁体   中英

C# Increasing Length of Command Prompt when Printing to Command Prompt

Okay so I admit this is a bit of a trivial problem, but I was hoping someone who has done some Windows development knows what I'm talking about here.

I made a C# code which takes all the words in the clipboard and prints them to the command prompt one on a line, alphabetically sorted (ignoring punctuation). HOWEVER, the problem lies in after the program is completed, so you cannot see all the words that were printed. The lines at the top get cut off.

This only happens with really long strings that have a lot of words, it blows through the available amount of lines you can scroll back up to see in the command prompt so you can't see everything the program printed.

Come to think of it, this is a common problem I've encountered when working with the Windows command prompt.

Is there any way to prevent this? Any workarounds? I'll continue to fiddle around and see if there is.

Use Console.SetBufferSize() like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM