-3

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?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
user1859829
  • 53
  • 3
  • 8

1 Answers1

2

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.

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • I understand, and i thank you for the help. this was exactly what i was asking for. now i just need to understand what happened in the code. but that will be on my own. i thank you again. – user1859829 Mar 25 '13 at 20:35