Access modifiers in C# are keywords used to define the accessibility or visibility of classes, methods, variables, and other members. They help control how and where these members can be accessed. Here's a concise overview of the main access modifiers in C#:
1. Public
2. Private
3. Protected
4. Internal
5. Protected Internal
6. Private Protected
Summary Table
Modifier |
Same Class |
Derived Class |
Same Assembly |
Other Assemblies |
public |
✔ |
✔ |
✔ |
✔ |
private |
✔ |
✘ |
✘ |
✘ |
protected |
✔ |
✔ |
✘ |
✘ |
internal |
✔ |
✔ |
✔ |
✘ |
protected internal |
✔ |
✔ |
✔ |
✔ (if derived) |
private protected |
✔ |
✔ |
✘ |
✘ |
These modifiers are essential for implementing encapsulation and controlling access to your code effectively.