Yes, it's possible to write text in different colors on the same line. But you have to change the foreground color for each different color. That is, if you want to write "My favorite fruit: " in blue, and "Apple" in red, then you have to do two Write
operations:
var originalColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("My farorite fruit: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Apple");
Console.ForegroundColor = originalColor;
If you want to do that with a single call, then you need some way to define that in a string. The .NET Framework does not provide such a facility. It's possible to build such a thing. It would involve writing a string parser similar to what's used by String.Format, where you define placeholders for which you supply values as parameters.
Perhaps a simpler way to do it is to write a method that takes a list of color and string pairs, something like:
public class ColoredString
{
public ConsoleColor Color;
public String Text;
public ColoredString(ConsoleColor color, string text)
{
Color = color;
Text = text;
}
}
public static void WriteConsoleColor(params ColoredString[] strings)
{
var originalColor = Console.ForegroundColor;
foreach (var str in strings)
{
Console.ForegroundColor = str.Color;
Console.Write(str.Text);
}
Console.ForegroundColor = originalColor;
}
public void DoIt()
{
WriteConsoleColor(
new ColoredString(ConsoleColor.Blue, "My favorite fruit: "),
new ColoredString(ConsoleColor.Red, "Apple")
);
}