문제

I'm Junior programmer I Wrote this Code in Console application

static void Main(string[] args)
{
    Console.BackgroundColor = ConsoleColor.Red;
    Console.WriteLine("backgroundcolor is red");
    Console.ForegroundColor = ConsoleColor.Green;
    Console.Write("ForegroundColor is Green");
    Console.ReadKey();
}

But I want to Write one console write line. So background color is red just with background color in console and Foreground Color is Green write in console application just with Foreground Color at a same time that each sentence effected with its class in one line.

도움이 되었습니까?

해결책

What about this...

static void Main(string[] args)
{
 var originalColor = Console.BackgroundColor;
 Console.BackgroundColor = ConsoleColor.Red;
 Console.Write("The background color is red. ");
 Console.BackgroundColor = originalColor;
 Console.ForegroundColor = ConsoleColor.Green;
 Console.Write("The foreground color is green");
 Console.ReadKey();
}

다른 팁

I think is what you want. Correct me if I am wrong.

static void Main(string[] args)
    {
        var originalColor = Console.BackgroundColor;
        Console.BackgroundColor = ConsoleColor.Red;
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("The BackgroundColor is " + Console.BackgroundColor.ToString() + " and the ForegroundColor is " + Console.ForegroundColor.ToString());
        Console.ReadKey();
    }

I think this will fix your problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top