私人的
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();
// Compile Error - not accessible due to private modifier
var someValue = foo.someProperty;
// Compile Error - not accessible due to private modifier
var baz = new Foo.Baz();
}
}