c# - C# 中的 "protected"方法?

标签 c# .net visual-studio oop access-modifiers

在 C# 中将方法定义为 protected 有什么好处?

喜欢:

protected void KeyDemo_KeyPress( object sender, KeyPressEventArgs e ) 
{
    // some code
}

与这样的东西相比:

private void FormName_Click( object sender, EventArgs e )
{
    //some code
}

我在很多书中看到过这样的例子,但我不明白为什么以及什么时候使用 privateprotected

最佳答案

可以从派生类调用 protected 方法。私有(private)方法不能。

这是私有(private)方法和 protected 方法之间的唯一区别。

关于c# - C# 中的 "protected"方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/930190/

相关文章:

c# - WPF 用户控件转换

c# - 无法访问 EventArgs 类型时如何使用反射添加事件处理程序?

c# - .Net 核心中 Json() 的小写属性名称

sql-server - 将程序集添加到缓存 : This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded 失败

c# - 在 WPF 应用程序中显示和筛选 XML 数据

c# - 使用带有 sql 查询的 ado.net 时计算年龄?

c# - 将 ISerializable 与 DataContractSerializer 一起使用时,如何阻止序列化程序输出类型信息?

visual-studio - Visual Studio 警告 C4133

c++ - 随机字符串数组的选择排序

c# - Entity Framework - 批量更新/插入/删除缓慢