1

How can I get current console colors (foreground/background)?

I have a method to output single line with changed foreground:

    public void ColorLine(string line, System.ConsoleColor foreground)
    {
        // maybe save original foreground color here

        // then change it 
        System.Console.ForegroundColor = foreground;

            // write line
            System.Console.WriteLine(line);

        // set original color
        System.Console.ForegroundColor = // original foreground color;
    }
q-l-p
  • 4,304
  • 3
  • 16
  • 36
ex-vi
  • 118
  • 1
  • 10

1 Answers1

4
// save original foreground color here
ConsoleColor currentForeground = Console.ForegroundColor;


// set original color
Console.ForegroundColor = currentForeground 
user1672994
  • 10,509
  • 1
  • 19
  • 32