0

what is the difference between

Console.SetWindowSize(20,30); 

and

Console.WindowWidth = 20; Console.WindowHeight = 30; 

?

2
  • 1
    Probably none, SetWindowSize() just breaks it down to a one-liner Commented Apr 13, 2018 at 15:30
  • 2
    It avoids the flicker you'd get from the window resizing itself twice. Commented Apr 13, 2018 at 15:33

2 Answers 2

4

The properties actually call the method. So if you choose the second option you call the method twice.

Here you can see the source code of the Console.WindowHeight property. In the setter the method is called in combination with the old Console.WindowWidth value.

Sign up to request clarification or add additional context in comments.

Comments

3

Absolutely nothing except using both of the properties does the operations twice. Here is the reference source:

public static int WindowWidth { [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] get { Win32Native.CONSOLE_SCREEN_BUFFER_INFO csbi = GetBufferInfo(); return csbi.srWindow.Right - csbi.srWindow.Left + 1; } [ResourceExposure(ResourceScope.Process)] [ResourceConsumption(ResourceScope.Process)] set { SetWindowSize(value, WindowHeight); } } public static int WindowHeight { [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] get { Win32Native.CONSOLE_SCREEN_BUFFER_INFO csbi = GetBufferInfo(); return csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } [ResourceExposure(ResourceScope.Process)] [ResourceConsumption(ResourceScope.Process)] set { SetWindowSize(WindowWidth, value); } } 

Notice how the two just call SetWindowSize with the new value and the current other value (height or width)?

If you really want to get down to gritty details, there is a bit of a difference. Because the properties call SetWindow and read the property of the other value, there is some native calls back-and-forth that happen to get that value. So using SetWindowSize is more performant than just setting the two properties because it doesn't have to GetBufferInfo in the property and create new objects. GetBufferInfo is also called by SetWindowSize so it avoids an extra call.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.