设置"Important"-留言红色,其他白色
Set "Important"-message red, other white
我正在创建一个日历,我想将重要的会议设置为红色,其他会议设置为白色。我怎样才能做到这一点?当我将最后一行的颜色设置为红色时,不重要的会议也是红色的。我的代码:
string important;
Console.Write("High priority? input yes or no: ");
important = Console.ReadLine();
if (important == "yes" || important == "Yes")
{
important = "Important";
}
else
{
important = "Normal";
}
Console.Write("Priority: " + important);
像这样使用Console.ForegroundColor
:
important = Console.ReadLine();
Console.Write("Priority: ");
if (important == "yes" || important == "Yes")
{
Console.ForegroundColor = ConsoleColor.Red ;
important = "Important";
}
else
{
Console.ForegroundColor = ConsoleColor.White;
important = "Normal";
}
Console.Write(important);
检查 Arghya C 的回答。
旧代码:
string important;
Console.Write("\n\nIs the meeting high priority?\n Input \"Yes\" or \"No\": ");
important = Console.ReadLine();
if (important == "yes" || important == "Yes")
{
Console.Write("\nPriority: \t");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Important");
}
else
{
Console.Write("\nPriority: \t");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Normal");
}
如果将 ForeGroundColor
更改为 Red
,则必须将其重置为默认颜色 Gray
。您可以使用此代码
Console.Write("High priority? input yes or no: ");
string important = Console.ReadLine();
if (important.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
{
Console.Write("Priority: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Important");
}
else
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Priority: Normal");
}
Console.ResetColor(); //default
我正在创建一个日历,我想将重要的会议设置为红色,其他会议设置为白色。我怎样才能做到这一点?当我将最后一行的颜色设置为红色时,不重要的会议也是红色的。我的代码:
string important;
Console.Write("High priority? input yes or no: ");
important = Console.ReadLine();
if (important == "yes" || important == "Yes")
{
important = "Important";
}
else
{
important = "Normal";
}
Console.Write("Priority: " + important);
像这样使用Console.ForegroundColor
:
important = Console.ReadLine();
Console.Write("Priority: ");
if (important == "yes" || important == "Yes")
{
Console.ForegroundColor = ConsoleColor.Red ;
important = "Important";
}
else
{
Console.ForegroundColor = ConsoleColor.White;
important = "Normal";
}
Console.Write(important);
检查 Arghya C 的回答。
旧代码:
string important;
Console.Write("\n\nIs the meeting high priority?\n Input \"Yes\" or \"No\": ");
important = Console.ReadLine();
if (important == "yes" || important == "Yes")
{
Console.Write("\nPriority: \t");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Important");
}
else
{
Console.Write("\nPriority: \t");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Normal");
}
如果将 ForeGroundColor
更改为 Red
,则必须将其重置为默认颜色 Gray
。您可以使用此代码
Console.Write("High priority? input yes or no: ");
string important = Console.ReadLine();
if (important.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
{
Console.Write("Priority: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Important");
}
else
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Priority: Normal");
}
Console.ResetColor(); //default