Access Modifiers in C# and ASP.net

What is an access modifier ?

Access modifiers are keywords used to specify accessibility of a member or a type. An access modifier allows us a way handle which member or type has an access or not has an access to certain features in a program. For example if you want to hide or encapsulate particular member or type outside the class scope then you achieve this through access modifier only or if you want to expose 

particular member or type outside the class scope then you achieve this through access modifier only.


Types of access modifiers

Private

Protected

Public

Internal

Protected Internal

 Public: When Members of a class are declared as public, then they can be accessed

1.    Within the class in which they are declared.

2.   Within the derived classes of that class available within the same assembly.

3.    Outside the class within the same assembly.

4.    Within the derived classes of that class available outside the assembly.

5.    Outside the class outside the assembly. 

Internal: When Members of a class are declared as internal, then they can be accessed

1.    Within the class in which they are declared.

2.   Within the derived classes of that class available within the same assembly.

3.    Outside the class within the same assembly.

Protected: When  Members  of  a  class  are  declared  as  protected,  then  they  can  be accessed

1.    Within the class in which they are declared.

2.   Within the derived classes of that class available within the same assembly.

3.    Within the derived classes of that class available outside the assembly.


Protected internal: When Members of a class are declared as protected internal, then they can be accessed

1.    Within the class in which they are declared.

2.    Within the derived classes of that class available within the same assembly.
3.    Outside the class within the same assembly.
4.    Within the derived classes of that class available outside the assembly.

Private: Private members of a class are completely restricted and are accessible only within the class in which  they are declared.
Read More »