Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colored console output [duplicate]

Tags:

c#

colors

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#?

like image 932
13aal Avatar asked Nov 01 '25 04:11

13aal


2 Answers

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.

like image 172
fulvio Avatar answered Nov 03 '25 19:11

fulvio


In a Console App you can do

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Hi I'm green");
Console.Read();
like image 40
etoisarobot Avatar answered Nov 03 '25 18:11

etoisarobot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!