what is the difference between
Console.SetWindowSize(20,30); and
Console.WindowWidth = 20; Console.WindowHeight = 30; ?
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.
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.
SetWindowSize()just breaks it down to a one-liner