“受保护" C#中的方法? [英] "protected" methods in C#?
本文介绍了“受保护" C#中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中将方法定义为protected
有什么好处?
What are the benefits to defining methods as protected
in C#?
喜欢:
protected void KeyDemo_KeyPress( object sender, KeyPressEventArgs e )
{
// some code
}
与类似这样的东西相比:
As compared to something like this:
private void FormName_Click( object sender, EventArgs e )
{
//some code
}
我在很多书中都看到过这样的例子,但我不明白为什么以及何时使用private
vs protected
?
I've seen such examples in many books and I don't understand why and when do they use private
vs protected
?
推荐答案
可以从派生类中调用受保护的方法.私有方法不能.
那是私有方法和受保护方法之间唯一的区别.
That's the one and only difference between private and protected methods.
这篇关于“受保护" C#中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文