【发布时间】:2013-03-18 10:23:50
【问题描述】:
我遇到了这个问题并正在寻找解决方案,但没有找到与我类似的情况。以下是我的情况:
在 X.cs 类文件中:
namespace BlaBla{
public class X{
public const string foo = "foo";
// other code
}
public class Y{
public const int bar = 0;
}
}
在其他课程中,我正在写作:
private const string someString = X.foo + Y.bar + "";
它一直给我一个编译错误:
The Expression assigned to someString must be constant
虽然它们都是不变的!当我删除 Y.bar 时,错误被删除,我不知道为什么。有什么帮助吗?
【问题讨论】:
标签: c# compiler-errors constants