. NET Learning 3rd Quarter C # Object-oriented access modifiers

Source: Internet
Author: User

. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.