Access Specifiers in C#

 

The visibility or accessibility of classes, methods, properties, and fields inside a program can be specified with the help of special keywords known as access specifiers in the C#. The parts of the code that are able to access and interact with particular items are precisely controlled by them. According to C#, there are four primary access specifiers.

 

  • public: Enables unrestricted access to a class member from any location within the code. 

 

  • Private Restricts access to a class member only within the same class, making it inaccessible from outside. 

 

  • protected: Enables inheritance-related access by restricting access to a class member within the same class and its derived classes.

 

  • internal: Allows access to a class member within the same assembly (project) but limits access from external assemblies. 

 


Related Question