我遇到了这个问题并正在寻找解决方案,但没有找到类似于我的情况。这就是我所拥有的:
在类文件 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 时,错误被删除,我不知道为什么。有什么帮助吗?