无法创建一个实例

问题描述:

这里后获得常数变量是我的C#类代码无法创建一个实例

public class ConstReadOnly 
{ 
    public const int cV = 10; 
    public readonly int rV = 40; 
} 

现在,当我尝试创建这个类我没有得到的const变量cV。什么可能是实例原因。

const隐含静态的,可以通过类名来访问他们像:

ConstReadOnly.cV 

您可能会看到这个帖子从乔恩斯基特 - Why can't I use static and const together?

因为常数implictly静态的。

如果您想使用它们,请使用类名称作为限定符。

int fromConstInt = ConstReadOnly.cV;