I'm just beginning to learn C# and am curious if there is an ASCII way to get colored output in the terminal, for example:
In Ruby I can do this:
puts "\e[32mThis will be green\e[0m"
In JavaScript I can do this:
function say(input){
console.log("\033[32m" + input + "\033[0m"
}
say("This will be green")
How can I do the same thing in C#?
C# you an use the following:
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("White on blue.");
Console.Read();
Remember you can also do this in JavaScript:
console.log('%cHello world', 'background-color: #0000FF; color: #FFFFFF');
Run the code snippet and then look at the JavaScript console.
In a Console App you can do
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Hi I'm green");
Console.Read();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With