cs11dotnet7/vscode/Chapter02/Arguments/Program.cs

33 lines
673 B
C#
Raw Normal View History

2022-02-13 17:03:32 +01:00
WriteLine($"There are {args.Length} arguments.");
foreach (string arg in args)
{
WriteLine(arg);
}
if (args.Length < 3)
{
WriteLine("You must specify two colors and cursor size, e.g.");
WriteLine("dotnet run red yellow 50");
return; // stop running
}
ForegroundColor = (ConsoleColor)Enum.Parse(
enumType: typeof(ConsoleColor),
value: args[0],
ignoreCase: true);
BackgroundColor = (ConsoleColor)Enum.Parse(
enumType: typeof(ConsoleColor),
value: args[1],
ignoreCase: true);
try
{
CursorSize = int.Parse(args[2]);
}
catch (PlatformNotSupportedException)
{
WriteLine("The current platform does not support changing the size of the cursor.");
}