Speaking of the differences between the four classes, it is necessary to explain a concept: an assembly. An assembly (Assembly), which can be simply understood as a. dll or. exe file generated after compilation, is a logical organization of the class library relative to namespace, which can be called the physical organization of the Program Class Library, described on MSDN as " Assemblies contain metadata that describes their own build numbers and the details of all the data and object types they contain. " A general scenario is that an assembly can contain one or more namespaces.
Public: Any method of any other class is visible;
Private: Members defined in this class are accessible only to methods of this class;
Protected: Members of this class can only access the methods of this class and the methods of inheriting classes of this class;
Internal: Members of this class are accessed only by methods of any class in the assembly in which the class is located;
Protected internal: For the protected and internal of the same set.
Therefore from the access level from high to low should be public>protected internal>internal>protected>private
The default modifier for a class is internal, and the default modifier for a member variable in a class is private,namespace, which can be considered a modifier public. Another point on MSDN also mentions that the access level of an inherited class cannot be greater than the access level of the inherited class, such as a class that internal cannot inherit from private.
Using System; /****************************** * chapter:c# Difficulty one by one (v) * Author: Wang Hongjian * date:2010-1-15 * blog:http://www.51obj.cn/* Email: walkingp@126.com * Description: Access modifier * ***************************/namespace Testmain {public class A {public void Aler T () {}} internal class B:a {internal new void Alert () {Console.WriteLine ("You"),}} class program {static void Main ( ) {b b=new B (); B.alert ();}} }
The above is the C # difficulty one by one (5): class type of access content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!