-3
我想知道如何結合代碼+ int /字符串c#結合代碼與字符串
例如。
string USERINPUT = Console.ReadLine();
Console.ForgroundColor = ConsoleColor.USERINPUT
但這不起作用。我怎麼想?
我想知道如何結合代碼+ int /字符串c#結合代碼與字符串
例如。
string USERINPUT = Console.ReadLine();
Console.ForgroundColor = ConsoleColor.USERINPUT
但這不起作用。我怎麼想?
對於分配
Console.ForegroundColor = (something here);
必須指定一個ConsoleColor,這是一個枚舉。
您可以從它的字符串等效中解析枚舉值。
Console.ForegroundColor =
(ConsoleColor)System.Enum.Parse(typeof(ConsoleColor), USERINPUT);
有關詳細信息,請參閱:
Search for a string in Enum and return the Enum
請注意,我的代碼不包括錯誤處理。如果用戶在不是ConsoleColor
成員的控制檯鍵入字符串,則會出現錯誤情況。
我明白了,我感謝你的幫助。這正是我所要求的。現在我只需要了解代碼中發生了什麼。但那將是我自己的。我再次感謝你。 – user1859829 2013-03-25 20:35:27
你會得到什麼錯誤? – 2013-03-25 20:24:55
我認爲這些錯誤非常明顯,即使沒有編譯器輸出。 – Inisheer 2013-03-25 20:26:34
system.consoleColor不包含USERINPUT的定義 – user1859829 2013-03-25 20:27:59