书中描述修饰class访问权限有四个级别:public、internal、protected、private做过一年C#,我见过public class ClassName{...},也见过internal class ClassName{...},但怎么就没见到private class ClassName{...} 和 protected class ClassName{...}呢?我不明白用private和protected声明类是什么意思,代表什么意义?类classc#
调试欢乐多
* Types declared in compilation units or namespaces can have public or internal declared accessibility and default to internal declared accessibility.
* Class members can have any of the five kinds of declared accessibility and default to private declared accessibility. (Note that a type declared as a member of a class can have any of the five kinds of declared accessibility, whereas a type declared as a member of a namespace can have only public or internal declared accessibility.)来自
3.5.1 Declared accessibility
http://msdn.microsoft.com/en-us/library/aa691127(v=vs.71).aspx
{
public class Nested
{
private Container parent; public Nested()
{
}
public Nested(Container parent)
{
this.parent = parent;
}
}
}参考:
Nested Types (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/ms173120.aspx
一般都是属性 方法、。
protected:受保护的
不是嵌套类不允许使用private, protected和protected internal
会报错:Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal