C # class (4)

The original link: https://csharp.net-tutorials.com/classes/visibility/

Visibility

Visibility controls the issue of access rights. The most common ones are private and public, only a few are introduced here

  1. public
       can be accessed anywhere. EnumerationEnum and interface interface are all public

  2. protected
       can only be derived from or inherited from this class

  3. internal
      The sameproject

  4. private
       Only the same kind can access, class and struct are all private
       For example, Class1 and Class2, the private members in Class1 can only be accessed by Class1, and Class cannot be accessed.
      We instantiate a Class1 in Class2, and so do we You can’t use its private variables, because you’re still Class2
       If Class2 inherits from Class1, then you can only access the non-private variables of Class1 in Class2, and the private ones can’t be accessed because they are not the same as Class (base class and derived class after all Not a class)  

share picture

?

Original link: https://csharp.net- tutorials.com/classes/visibility/

Visibility

Visibility controls access permissions. The most common one is< code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid #eaeaea; background-color: #f8f8f8; border-radius: 3px; display: inline;">private and public , Only a few are introduced here

  1. public
       can be anywhere Visited. EnumerationEnum and interface interface are all public

  2. protected
       can only be derived from or inherited from this class

  3. internal
      The sameproject

  4. private
       Only the same kind can access, class and struct are all private
       For example, Class1 and Class2, the private members in Class1 can only be accessed by Class1, and Class cannot be accessed.
      To instantiate a Class1 in Class2, we can’t use it either Its private variables, because you are still Class2
       If Class2 inherits from Class1, then only the non-private variables of Class1 can be accessed in Class2, and the private ones cannot be accessed because they are not the same Class (the base class and the derived class are not the same after all Class)  

share pictures

?

?

Leave a Comment

Your email address will not be published.