c# - 面向对象编程基本概念(C#)

标签 c# asp.net oop inheritance abstraction

据我们所知

默认修饰符

  • 类别
  • 结构
  • 委托(delegate)
  • 界面
  • 枚举

内部

  1. 枚举和接口(interface)成员默认公共(public)

  2. 默认情况下,Class、Struct 和 Delegate 成员都是私有(private)

  3. 同一类库的非派生类可以访问公共(public)类和内部类 (以及公共(public)、内部、 protected 内部成员)。

  4. 不同类库的非派生类可以访问公共(public)类 (仅限公众成员)。

  5. 不同类库的派生类可以访问公共(public)类 (公共(public)、 protected 、 protected 内部成员)。

现在我想了解核心概念,为什么是这样......

protected 成员的范围比内部成员更大?

最佳答案

来自docs :

protected

The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal

The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

关于c# - 面向对象编程基本概念(C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13063412/

相关文章:

c# - 从 c# (SharePoint 2010) 使用 wkhtmltopdf

c# - Crystal Report - 横向和纵​​向导出为 PDF

php - 如何在执行操作之前确保对象存在

c# - 在 OOP 中可以处理对象类外部的对象事件吗?

c# - 在并行运行 RESTFul 服务的同时通过 WCF 运行 SOAP API

c# - c#中数值递增的问题

asp.net - 防止表单中的 ASP.NET 文本框提交表单

javascript - 如何使用 UpdatePanel 触发 Selected Index Changed 事件而不进行任何回发?

使用 std 安全指针相互链接的 c++ 类 (c++)

c# - 在运行时授予管理员权限