0% found this document useful (0 votes)
11 views

Access Specifiers and Access Modifiers in C#

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Access Specifiers and Access Modifiers in C#

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ACCESS SPECIFIERS

OR ACCESS
MODIFIERS IN C#
ACCESS MODIFIERS

• C# provides you with access modifiers that allow you to specify


which classes can access the data members of a particular class.
• In C#, there are four commonly used access modifiers
• public
• private
• protected
• Internal
ACCESS MODIFIERS
APPLICABLE TO APPLICABLE TO APPLICABLE TO APPLICABLE TO APPLICABLE TO
THE THE CURRENT THE DERIVED OUTSIDE THE OUTSIDE THE
APPLICATION CLASS CLASS NAMESPACE / NAMESPACE
ASSEMBLY BUT IN DERIVED
CLASS

PUBLIC YES YES YES YES YES

PRIVATE NO YES NO NO NO

PROTECTED NO YES YES NO YES

INTERNAL YES YES YES NO NO


RULES FOR ACCESS MODIFIERS

• Members of same class can access each other.


• Only Public and internal access modifiers are used with
the class.
ACCESS MODIFIERS

• PUBLIC: The public access modifier provides the most permissive


access level.
• The members declared as public can be accessed anywhere in the
class as well as from other classes.
• PRIVATE: The private access modifier provides the least
permissive access level.
• Private members are accessible only within the class in which they
are declared.
ACCESS MODIFIERS

• PROTECTED: The protected access modifier allows the


class members to be accessible within the class as well as
within the derived classes.
ACCESS MODIFIERS

• INTERNAL: The internal access modifier allows the class


members to be accessible only within the classes of the
same namespace / assembly.
• An assembly is a file that is automatically generated by the
compiler upon successful compilation of a .NET
application.
• The code declares a variable called NumOne as internal,
which means it has only assembly-level access.

You might also like