[英]Private const defined on class level and then used on an attribute, why this compile?
Have a look at the following code: 看下面的代码:
public class Person
{
private const string MyConst = "SomeValue";
[MyAttribute(MyConst)]
public string Name {get;set;}
}
MyConst
is defined as private
and in my opinion it should not be accessible for MyAttribute. MyConst
被定义为private
,我认为MyAttribute应该不可访问。 However this code compiles well. 但是,此代码编译良好。
Anyone knows the reason? 有人知道原因吗?
Private members are only accessible within the same class body as where they're declared. 私有成员只能在与其声明的地方相同的类体内访问。 I guess it's accessible because you're declaring and using it in the same class. 我猜它是可访问的,因为您在同一个类中声明和使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.