Search code examples
c#syntax

Change Colour Of Text Mid-Way?


So Basically, I Want to make just one word yellow colour, and the rest White, so what i did is:

Console.Write("Words ");
Console.ForegroudColor = ConsoleColor.Yellow;
Console.Write("Words ");
Console.ForegroudColor = ConsoleColor.White;
Console.Write("Words ");

is there a way for it to be done easier?

EX: (not working)

Console.Write("Words " + Console.ForegroudColor = ConsoleColor.Yellow; + "Words");

Solution

  • Not something built in - however I have an open source project called ExtendedConsole on GitHub that does exactly that, using simple xml-based markup.

    The documentation is hosted on GitHub pages and you can download it as a nuget package.

    and use it like this:

    exConsole.Write("Some words here <c f='yellow'>This is yellow!</c> some more words here");
    

    It also contains many other things that can make your life easier when writing console applications such as menus and read methods.