The purpose of an access specifier is to define the scope and visibility of a class member.
C# provides five access specifiers: public, private , protected , internal and protected internal.
- Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.
- Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.
- Protected access specifier allows a child class to access the member variables and member functions of its base class.
- Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the assembly in which the member is defined.
- Protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except child class within the same assembly.
[amazon_link asins=’8126538791,1788398076,1893115860,B01HVJZLQA,1491927062,1788478924,0198097409,1946383082,1430242337|1840787198,1430249358,1788398076,0735615683,0321637003,1118336925,1430235306,1491987650,1491988533′ template=’ProductGrid’ store=’desibanjara22-21|desibanjaraco-21′ marketplace=’IN|UK’ link_id=’45042f94-94df-11e8-aa61-7f817e4cc1dd’]