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?
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?
For the assignment
Console.ForegroundColor = (something here);
you must assign a ConsoleColor, which is an enum.
You can parse an enum value from it's string equivalent.
Console.ForegroundColor =
(ConsoleColor)System.Enum.Parse(typeof(ConsoleColor), USERINPUT);
For details see:
Search for a string in Enum and return the Enum
Note that my code does not include error handling. If the user types in a string at the console that is not a member of ConsoleColor
, you will get an error condition.