Class Accessibility Matrix Diagram
What is Default accessibility of class
- Internal
Difference between Internal and Protected Internal
- Look above image for clarification
1. Public
- Accessibility: The class is accessible from any other class or assembly.
- Usage: When you want the class to be widely accessible.
|
|
2. Internal
- Accessibility: The class is accessible only within the same assembly (project).
- Usage: When you want to limit access to within the assembly, which is useful for encapsulation.
|
|
3. Protected
- Accessibility: The class itself cannot be protected, but its members can be. A class can be derived from a base class with protected members.
- Usage: When you want to allow access to members only in derived classes.
|
|
4. Private
- Accessibility: A class itself cannot be private, but its members can be. Private members are only accessible within the same class.
- Usage: When you want to restrict access to the class members to only within the class itself.
|
|
5. Protected Internal
- Accessibility: The class or member is accessible within the same assembly and also to derived classes in other assemblies.
- Usage: Useful for situations where you want to expose class members to derived classes or within the assembly.
|
|
6. Private Protected
- Accessibility: The class or member is accessible within the same class or in derived classes that are in the same assembly.
- Usage: A more restrictive version of
protected internal
, useful for fine-grained access control.
|
|