我有一个char数组,我想从控制台分配值.这是我的代码:
char[] input = new char[n];
for (int i = 0; i < input.Length; i++)
{
input[i] = Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
无法将类型'System.ConsoleKeyInfo'隐式转换为'char'
有没有一种简单的方法来解决这个问题?
Kam*_*ski 30
使用Console.ReadKey然后KeyChar获取char,因为ConsoleKeyInfo不能char像你的错误那样分配.
input[i] = Console.ReadKey().KeyChar;
Run Code Online (Sandbox Code Playgroud)