When talking about the differences between the four categories, it is necessary to explain a concept: Program Set. The program set (assembly.pdf can be simply translated into the. dllor. EXE file generated after compilation. Compared with namespace, it is the logical organization form of the class library. It can be called the physical organization form of the program class library, on msdn, the description "Assembly contains metadata that describes their own version numbers and details of all the data and object types they contain ". Generally, an assembly can contain one or more namespaces.
Public: visible to any method of any other class;
PRIVATE: the members defined in this class can only access the methods of this class;
Protected: only the methods of this class and the methods that inherit the class can be accessed by members of this class;
Internal: Members of this class can only access the methods of any class in the Assembly where the class is located;
Protected internal: the Union of protected and internal.
Therefore, the access level should be public> protected internal> protected> private.
The default modifier of the class is internal, the default modifier of the member variables in the class is private, and namespace can be considered as public. In addition, the access level of the inherited class cannot be higher than the access level of the inherited class. For example, the internal class cannot inherit the private class.CopyCodeThe Code is as follows: using system;
/******************************
* Chapter: C # difficulties one by one (5)
* Author: Wang Hongjian
* Date: 2010-1-15
* Blog: http://www.51obj.cn/
* Email: walkingp@126.com
* Description: access modifier
****************************/
Namespace testmain
{
Public Class
{
Public void alert ()
{
}
}
Internal Class B:
{
Internal new void alert ()
{
Console. writeline ("you ");
}
}
Class Program
{
Static void main ()
{
B = new B ();
B. Alert ();
}
}
}