msdn中讲解得很详细啊!
internal是一个访问修改器,它就像其他的访问修改器如public,private,protected一样,用来限制对类型或类型成员的访问。
被声明为internal的类型或者类型成员,只能被在同一个assembly中的其他部分访问,下面是来自msdn中的例子:Example:This example contains two files, Assembly1.cs and Assembly2.cs. The first file contains an internal base class, BaseClass. In the second file, an attempt to access the member of the base class will produce an error.File Assembly1.cs:// Assembly1.cs
// compile with: /target:library
internal class BaseClass 
{
   public static int IntM = 0;
}File Assembly2.cs// Assembly2.cs
// compile with: /reference:Assembly1.dll
// CS0122 expected
class TestAccess 
{
   public static void Main() 
   {
      BaseClass myBase = new BaseClass();   // error, BaseClass not visible outside assembly
   }
}上面的例子是把Assembly1编译成了一个dll,Assembly2是另外一个Assebly的应用程序,由于Assembly1中的BaseClass类被声明为internal,所以Assembly不能访问这个类。但是如果你把BaseClass类移到Assembly2中,那么就没有问题,哪怕它是声明为internal。下面是msdn的原文:
A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework.译文:
internal通常用在基于组件的开发中,因为它让一组组件以一种私有的方式协同工作,而不被暴露给应用程序代码的其他部分。例如:一个框架为了建立图形用户界面,可以提供Control和Form类,这些类中使用了带有internal访问的成员来协同操作。由于这些成员是internal的,它们没有暴露给使用框架的代码。