C# 基本代码(首次编码)错误(visual studio 2015 for desktop express)

C# 基本代码(首次编码)错误(visual studio 2015 for desktop express),c#,C#,我得到了上面代码的以下错误,如何修复这些错误 Console.WriteLine("Type a number, Any number!"); ConsoleKeyInfo KeyInfo = Console.ReadKey(); if (KeyInfo.KeyChar -- 'a') { Console.WriteLine("Thats not a number, Knock it off!");

我得到了上面代码的以下错误,如何修复这些错误

        Console.WriteLine("Type a number, Any number!");
        ConsoleKeyInfo KeyInfo = Console.ReadKey();

        if (KeyInfo.KeyChar -- 'a')
        {
            Console.WriteLine("Thats not a number, Knock it off!");
        }

        Console.WriteLine("Did you press {0}", KeyInfo.KeyChar.ToString());
    }
}
获取由当前对象表示的Unicode字符。所以它是一个只读属性,这意味着你不能修改这个属性的值

通过查看代码,您似乎希望检查
if
条件中的字符
a
。因此,只需像这样使用(相等运算符)
=

CS1026 ) expected
CS1002 ; expected
CS0200 Property or Indexer 'ConsoleKeyInfo.KeyChar' Cannot be assigned to -- it is read only
CS1513 } expected
if (KeyInfo.KeyChar == 'a')