Part 13  Access Modifiers


Access modifiers are an integral part of object-oriented programming. Access modifiers are used to implement level of permission to access properties and methods. By declaring these access modifiers, we are defining a variable or an event can be accessed from assembly to within that class. Let's see how.
In C# there are 6 different types of Access Modifiers.
  1. private
  2. public
  3. protected
  4. internal
  5. protected internal
  6. Private Protected (C# version 7.2 and later)

Private Access Modifier :

This access modifier that can be implements, class, methods and variables only access within the class itself.It can't be used from outside of the class. As you declare a private constructor of a class, that class can't be accessed from outside that class, you can't create an object of that class,

Public Access Modifier :

We can access Class ,Method ,Global variable ,Instance Variable are access the outside of the class,library , package.


Protected Access Modifier :

We can access allows variables and methods to access from that class and the sub class of the class. That means that methods can be accessed within that class and from the classes, which actually inherit that class.


Internal
Internal members are accessible only within files in the same assembly (.dll).


Protected Internal:
A protected internal member is accessible from any class in the same assembly, including derived classes.
  1. Public: Anywhere from the class
  2. Private: Only within the class
  3. Protected: Only within that class and the sub classes of that class
  4. Internal: Within the assembly of the class
  5. Protected Internal: Within that class, sub classes of that class and and assembly