嘿。
我正在尝试自己学习升 C,但我在将输入作为角色时遇到了问题。我的代码部分是:
var foodTypeMap = new Dictionary<string, string>();
foodTypeMap["1"] = "Soups";
foodTypeMap["2"] = "Vegetables";
foodTypeMap["3"] = "Mains";
foodTypeMap["4"] = "Deserts";
...
...
string fType = Console.ReadLine();
string dishType = " ";
//if else statements here.. etc
dishType = foodTypeMap[fType];
通过这种方式,我可以将 fType 获取为整数并以此初始化 discType。我想通过像 x 代表汤和 q 代表沙漠的字符来获得选择。我试过了
Using Console.ReadLine()[0]
Using Console.ReadKey().KeyChar
Using Char.TryParse()
Using Convert.ToChar()
但做不到。有没有人可以帮助我理解这一点?