internal 修饰符起什么作用?

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 110 收藏 0 点赞 0 评论 0

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;

}

}

评论列表
文章目录