. Net Video Learning 3rd-quarter C # Object-oriented
Object-oriented access modifiers
C # five access modifiers
1) There are only two access modifiers that can be decorated for a class: Public,internal (Default)
Internal: can only be accessed in the current assembly (first understood as a project)
Public: Common
Project a accesses the public class in project B, where you first add Project B to the reference in Project A, and then add the namespace of the using Project B to the file in Project A.
In the same assembly, public and internal access rights are the same.
2) The access modifier for members of the decorated class: Public,private,protected,internal,internal protected
In the same project, internal has higher access rights than protected, and protected is higher than internal in different projects.
For example, there is internal class A in project A, there are protected members data_a, there is a public class AA inherits from A. In Project A, you can access member data_a through an object of AA, because AA inherits from a and data_a is protected, and you can access AA in Project B, because AA is the public class, but cannot access a because a is a internal class-- However, in Project B it is possible to access the data_a through AA. In fact, this is not allowed because the subclass exposes the members of the parent class, so the subclass's access rights cannot be higher than the parent class .
Internal protected is accessible only within the class inside the current assembly and within that class subclass.
. NET Learning 3rd Quarter C # Object-oriented access modifiers