私人的
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();
}
}