3.5 Access Modifiers
Access modifier describes the scope of accessibility of an object and its members. All C# types and type members have an accessibility level. We can control the scope of the member object of a class using access specifiers. We are using access modifiers for providing security of our applications. When we specify the accessibility of a type or member we have to declare it by using any of the access modifiers provided by the C# language.
Keyword
Applicable To
Meaning
public
Class, Member
No restrictions
protected
Member
Access limited to the class and derived class
private
Member
Access limited to the class
internal
Class, Member
Access limited to the current assembly
protected internal
Member
Access limited to the current assembly and derived types
Public
Public is the most common access specifier in C#. It can be accessed from anywhere, that means there is no restriction on accessibility. The scope of the accessibility is inside the class as well as outside. The type or member can be accessed by any other code in the same assembly or another assembly that references it.
Protected
The scope of accessibility is limited within the class or struct and the class derived (inherited) from this class.
Private
The scope of the accessibility is limited to only inside the classes or structs in which they are declared. The private members cannot be accessed outside the class and it is the least permissive access level.
Internal
The internal access modifiers can access within the program that contain its declarations and also access within the same assembly level but not from another assembly.
Protected Internal
Protected internal is the same access level of both protected and internal. It can access anywhere in the same assembly, the same class, and the classes inherited from the same class.
Next: Arrays
Last updated