C # access Modifiers

Source: Internet
Author: User

encapsulation is defined as "enclosing one or more items in a physical or logical package". In the object-oriented programming methodology, encapsulation is designed to prevent access to the implementation details.

Abstraction and encapsulation are the related features of object-oriented programming. Abstraction allows for the visualization of related information, and encapsulation enables the programmer to achieve the desired level of abstraction .

Encapsulation is implemented by using access modifiers . An access modifier defines the scope and visibility of a class member. The access modifiers supported by C # are as follows:

    • Public
    • Private
    • Protected
    • Internal
    • Protected Internal

1 , Public access Modifiers

The public access modifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed by an external class.

2 , Private access Modifiers

The Private access modifier allows a class to hide its member variables and member functions from other functions and objects. Only a function in the same class can access its private members.   Even an instance of a class cannot access its private members. 3 , Protected access Modifiers

The Protected access modifier allows subclasses to access the member variables and member functions of its base class. This helps to implement inheritance. We will discuss this in detail in the inherited chapters. Discuss this in more detail.

4.Internal access modifier

The Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current program. In other words, any member with the internal access modifier can be defined to be accessed by any class or method within the application defined by that member.

5 , Protected Internal access Modifiers

The Protected Internal access modifier allows a class to hide its member variables and member functions from other class objects and functions other than subclasses within the same application. This is also used to implement inheritance.

C # 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.