image

编辑人: 青衫烟雨

calendar2025-02-26

message1

visits142

internal 修饰符起什么作用?

internal 修饰符可以用于类型或成员,使用该修饰符声明的类型或成员只能在同一程集内访问

接口的成员不能使用 internal 修饰符

值得注意的是,如果为 internal 成员加上了 protected 修饰符,这时的访问级别为 internal 或 protected。只是看字面意思容易弄错,许多人认为 internal protected 应该是"只有同一个程序集中的子类可以访问",但其实它表示"同一个程序集中的所有类,以及所有程序集中的子类都可以访问"

示例

Example05Lib 项目的 Class1

using System;

using System.Collections.Generic;

using System.Text;

namespace Example05Lib

{

public class Class1

{

internal String strInternal = null;

public String strPublic;

internal protected String strInternalProtected = null;

}

}



喵呜刷题:让学习像火箭一样快速,快来微信扫码,体验免费刷题服务,开启你的学习加速器!

创作类型:
原创

本文链接:internal 修饰符起什么作用?

版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。
分享文章
share