Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
看看下面的代码:
public class Person { private const string MyConst = "SomeValue"; [MyAttribute(MyConst)] public string Name {get;set;} }
MyConst被定义为private并且在我看来它不应该被 MyAttribute 访问。然而,这段代码编译得很好。
MyConst
private
有人知道原因吗?
私有成员只能在与声明它们的地方相同的类体内访问。我想它是可以访问的,因为你在同一个类中声明和使用它。