i am wondering how to combine code + int/string
example.
string USERINPUT = Console.ReadLine();
Console.ForgroundColor = ConsoleColor.USERINPUT
but that does not work. how to i wonder?
对于作业
Console.ForegroundColor = (something here);
您必须分配一个ConsoleColor,它是一个枚举。
您可以从其等效字符串中解析枚举值。
Console.ForegroundColor =
(ConsoleColor)System.Enum.Parse(typeof(ConsoleColor), USERINPUT);
详情见:
请注意,我的代码不包括错误处理。如果用户在控制台输入不是 成员的字符串ConsoleColor
,您将收到错误情况。