Setting Option with Arguments and Handling Platforms
Learn how to use command-line arguments to set console window colors, cursor size and handle platform differences in the C#.
We will now use these arguments to allow the user to pick a color for the output window's background, foreground, and cursor size. The cursor size can be an integer value from 1, meaning a line at the bottom of the cursor cell, up to 100, meaning a percentage of the height of the cursor cell.
Setting options with arguments
We have statically imported the System.Console
class. It has properties like ForegroundColor
, BackgroundColor
, and CursorSize
that we can now set just by using their names without needing to prefix them with Console
. The System
namespace is already imported so that the compiler knows about the ConsoleColor
and Enum
types:
Step 1: Add statements to warn the user if they do not enter three arguments, and then parse those arguments and use them to set the color and dimensions of the console window, as shown in the following code:
Get hands-on with 1400+ tech skills courses.