You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a user-friendly command-line application, and as such I wanted to color my output to the console. However, I found myself frequently writing code like this:
Console.WriteLine("This output is white on black.");
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Green;
Console.WriteLine("This output is red on green.");
Console.ResetColor();
Console.WriteLine("This output is white on black.");
I thought it might be a lot easier for Console to have an overload on Write and WriteLine that takes in two ConsoleColor elements as arguments for the ForegroundColor and BackgroundColor variables and abstracts this process away from the developer. This way, the process of setting the ForegroundColor and BackgroundColor variables, writing to the console, and resetting the color can be written as one line in code. In that case, the above example might look like this:
Console.WriteLine("This output is white on black.");
Console.WriteLine("This output is red on green.", ConsoleColor.Red, ConsoleColor.Green);
Console.WriteLine("This output is white on black.");
If overloading is not possible, additional methods like WriteColor and WriteLineColor would still be very useful in my opinion.
The text was updated successfully, but these errors were encountered:
I'm trying to create a user-friendly command-line application, and as such I wanted to color my output to the console. However, I found myself frequently writing code like this:
I thought it might be a lot easier for
Console
to have an overload onWrite
andWriteLine
that takes in twoConsoleColor
elements as arguments for theForegroundColor
andBackgroundColor
variables and abstracts this process away from the developer. This way, the process of setting theForegroundColor
andBackgroundColor
variables, writing to the console, and resetting the color can be written as one line in code. In that case, the above example might look like this:If overloading is not possible, additional methods like
WriteColor
andWriteLineColor
would still be very useful in my opinion.The text was updated successfully, but these errors were encountered: