gpt4 book ai didi

c# - 如何使用 console.writeline 以不同颜色显示格式化输出

转载 作者:行者123 更新时间:2023-11-30 14:07:46 25 4
gpt4 key购买 nike

是否可以用不同颜色显示格式化输出:

console.WriteLine(“First {0} second{1} ”,  firstString, secondString)

我想在显示输出时显示一个变体,例如一种颜色的 firstString 和另一种颜色的 secondString

最佳答案

如果你想在一行中使用不同的颜色,你应该使用 Console.Write() 像这样写:

Console.ForegroundColor = ConsoleColor.White;
Console.Write("First ");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("{0} ", firstString);
Console.ForegroundColor = ConsoleColor.White;
Console.Write("second ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("{0} ", secondString);

关于c# - 如何使用 console.writeline 以不同颜色显示格式化输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38431068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com