✏️ Explanatory Question

Which are the access modifiers available in C#?

👁 527 Views
📘 Detailed Answer
💡

Answer with Explanation

Following are the access modifiers generally used for accessibility:

  • Public: If you define an attribute or method as public, it can be accessed from any code of the project.
  • Private: A private defined attribute or method can be accessed by any code within the containing class only.
  • Protected: If you define the method or attribute as protected it can be accessed by any method in the inherited classes and any method within the same class.
  • Internal: If you define an attribute or a method as internal, it is restricted to classes within the current position assembly.
  • Protected internal: If you define an attribute or method as protected internal, access is restricted to classes within the current project assembly or types derived from the containing class.