如果方法iAmPrivate
是Private
那么以下如何执行它?如果我尝试运行 PrivateMethod 的 myPrivateMethod 它被封装,为什么不同样适用于iAmPrivate
?
class PrivateMethod {
private int myPrivateMethod() {
return 1;
}
}
static void Main(string[] args) {
Program myProgram = new Program();
myProgram.iAmPrivate("private");
myProgram.iAmPublic("public");
PrivateMethod pm = new PrivateMethod();
//Console.WriteLine("this won't run {0}", pm.myPrivateMethod); //not possible
Console.WriteLine("press [enter] to exit");
Console.ReadLine();
}
public void iAmPublic(string s) {
Console.WriteLine("I am {0}", s);
}
private void iAmPrivate(string s) {
Console.WriteLine("I am {0}", s);
}