在 Visual Studio 2015 中运行以下代码
class Program
{
static void Main(string[] args)
{
const int a = 0;
a = 5;
}
}
显然 会生成编译器错误,但错误是:
The left-hand side of an assignment must be a variable, property or indexer
我接受代码应该生成编译器错误,但这个措辞对我来说没有多大意义,因为赋值的左侧 (a
) 是一个变量 - an整数变量(恰好是常量)
为什么我的 a
变量没有被识别为变量?
最佳答案
关于c# - 常量修改编译报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39399978/