辅助功能级别:受保护和私有之间有什么区别

Gib*_*boK 0 c# oop

能否帮助我理解私有方法和受保护方法的区别.关于http://msdn.microsoft.com/en-us/library/ba0a1yw2%28v=VS.71%29.aspx 我无法理解它,特别是短语"Private:Access仅限于包含类型. "

谢谢你的帮助.再见!

Jag*_*mag 8

class Test
{
  private method myMethod()
   {}
  protected method myprotectedMethod()
   {}
}


class ChildTest : Test
{
  public method useProtectedBaseMethod ()
  {
     this.myProtectedMethod(); // this is ok
     this.myMethod(); // this is NOT ok. will throw an Error
  }
}

class outsider
{
  Test  objTest = new Test();
  objTest.myProtectedMethod(); // throws an error as it is not accessible
  objTest.myMethod(); // throws an error as it is not accessible
}
Run Code Online (Sandbox Code Playgroud)