Tutorial: 12 - Access Specifiers
Access specifiers are used for controlling the access of members of class. There are 5 types of access specifiers in C#.
- Private
- Public
- Internal
- Protected
- Protected Internal
Private
It is used for limiting access of members within the class or types for example if members of a class are private then you can access only within the class not outside the class. By default if no access specifier is used, class members are private.
Public
If members or types are declared public, then these can be accessed outside class, inside assembly or even outside of assembly.
Internal
When you want to allow access of members or types within the assembly, you need to set them as internal so these will be accessible within the assembly in .NET framework.
Protected
Protected is used when use of inheritance is required, Using protected as access specifier will allow members to be accessible in child class.
Protected Internal
Using the protected internal will result in combined effect of both protected and internal. Members will be accessible within the assembly as well as with usage of inheritance.
No comments:
Post a Comment