menu

Search This Blog

Part 4 :- Access Specifiers or Access Modifiers in C#.Net

 Access Specifiers or Access Modifiers in C#.Net


Watch Video


Ø  Access Modifiers are keywords that define the accessibility of a member, class or datatype in a program. These are mainly used to restrict unwanted data manipulation by external programs or classes.

Ø  There are 4 access modifiers, but we can use  6 accessibility levels 





public: The type or member can be accessed by any other code in the same assembly or another assembly that references it. The public keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members.


private: The type or member can be accessed only by code in the same class or struct. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared.


protected: The type or member can be accessed only by code in the same class, or in a class that is derived from that class. A protected member of a base class is accessible in a derived class only if the access occurs through the derived class type. 


internal: The type or member can be accessed by any code in the same assembly, but not from another assembly. Internal types or members are accessible only within files in the same assembly. A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate by using members with internal access. Since these members are internal, they are not exposed to code that is using the frame work. It is an error to reference a type or a member with internal access outside the assembly within which it was defined. 


protected internal: The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly. The protected internal keyword combination is a member access modifier. A protected internal member is accessible from the current assembly or from types that are derived from the containing class. 


private protected: The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class. The private protected keyword combination is a member access modifier. A private protected member is accessible by types derived from the containing class, but only within its containing assembly. A private protected member of a base class is accessible from derived types in its containing assembly only if the static type of the variable is the derived class type.