...

/

Access Modifiers

Access Modifiers

Learn to control the visibility of methods and other class members.

All class members have access modifiers. We already encountered them when we decorated our classes with the public keyword.

Access modifiers define a context in which a given class or its member can be used.

  • The public modifier makes a class or its member public to all external code. They can be accessed from any other part of the program and even from a different program or assembly.
  • The private modifier makes a class or its member closed to the external environment. A private class can only be accessed from the class where it’s defined. We can’t make a class private on the namespace level. Members that are private can only be accessed from within the class where they’re defined.
  • The protected modifier can only be used with class members. These members are only accessible from the same class or any derived class.
  • With the internal modifier,
...