的private关键字标记属性,方法,字段和嵌套类为仅在类中使用:
public class Foo() { private string someProperty { get; set; } private class Baz { public string Value { get; set; } } public void Do() { var baz = new Baz { Value = 42 }; } } public class Bar() { public Bar() { var myInstance = new Foo(); // 编译错误-由于private修饰符而无法访问 var someValue = foo.someProperty; // 编译错误-由于private修饰符而无法访问 var baz = new Foo.Baz(); } }