在 C# 中将方法定义为 protected
有什么好处?
喜欢:
protected void KeyDemo_KeyPress( object sender, KeyPressEventArgs e )
{
// some code
}
与这样的东西相比:
private void FormName_Click( object sender, EventArgs e )
{
//some code
}
我在很多书中看到过这样的例子,但我不明白为什么以及什么时候使用 private
与 protected
?
最佳答案
可以从派生类调用 protected 方法。私有(private)方法不能。
这是私有(private)方法和 protected 方法之间的唯一区别。
关于c# - C# 中的 "protected"方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/930190/