Search code examples
c#windows-console

Is there a limit on the output of Console Window?


Code:
This program checks if the 2 numbers entered and their sum are divisible by the numbers 2 - 9, and displays the remaining divisible numbers (excluding the one being reviewed).

static void Main(string[] args)
{
    for (int i = 2; i < 10; i++)
    {
        Challenge(2, 6, i);
    }
    Console.ReadLine();
}

static void Challenge(int num1, int num2, int Divisor)
{
    int sum = num1 + num2;
    bool SumDivisible = sum % Divisor == 0;
    bool num1Divisible = num1 % Divisor == 0;
    bool num2Divisible = num2 % Divisor == 0;

    int highNum = 80;
    List<int> NumbersDivisible = Enumerable.Range(1, highNum).Where(x => x % Divisor == 0).ToList();

    // Use the booleans to determine output.
    if (SumDivisible || num1Divisible || num2Divisible)
    {
        if (SumDivisible)
        {
            Console.WriteLine("The SUM ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", sum, Divisor);
            outputListExceptInt(NumbersDivisible, sum);
            //output
            Console.WriteLine("\n\n");
        }
        if (num1Divisible)
        {
            Console.WriteLine("The FIRST number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num1, Divisor);
            outputListExceptInt(NumbersDivisible, num1);
            //output
            Console.WriteLine("\n\n");
        }

        if (num2Divisible)
        {
            Console.WriteLine("The SECOND number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num2, Divisor);
            outputListExceptInt(NumbersDivisible, num2);
            //output
            Console.WriteLine("\n\n");
        }
    }
    else
    {
        Console.WriteLine("The NUMBERS chosen and their SUM are not divisble by {0}. \nThe USABLE numbers for {0} are:\n", Divisor);
        outputListExceptInt(NumbersDivisible);
        Console.WriteLine("\n\n");
    }
}

public static void outputListExceptInt(List<int> NumbersDivisibleByDivisor, int except = 0)
{
    var Numbers = except > 0 ? NumbersDivisibleByDivisor.Where(x => x != except) : NumbersDivisibleByDivisor;
    foreach (int num in Numbers)
    {
        Console.WriteLine(num);
    }
}

Problem:
I'm finding that when I set the range (highNum) to anything over 89, a noticeable portion from the top of the window gets cut off:

highNum = 89:
highNum at 89

highNum = 90:
highNum at 90

Its cutting off 6 lines just with that small jump, and I'm not sure why.

Question:
My best guess is that there must be some limit on the output that can be displayed by the Console Window. Is this correct, or is something else causing this issue?


Solution

  • In a console window, click on Defaults

    enter image description here

    This opens a dialog box that allows you to set the scrollback buffer size (max number of lines to retain) by default in all of your console windows.

    enter image description here

    In my screenshot it is set to 9000 because I often log output to a console, and sometimes need to be able to scroll way back.

    You can also modify it from your program for the console it is running in using Console.SetBufferSize().