You are on page 1of 11

#Vision2025

Session:11 [Access Modifiers Types]


www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Introduction

Access modifiers are keywords used to specify the declared accessibility


of a member or a type. These define the permission level to type
members ( Methods, Properties, Events, Variables).

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Background

All type and type members have an accessibility level which controls
whether they can be used by the code in the same assembly in which
the type declared or the code in the other assembly.

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

C# provides The following access modifiers:

• private
• protected
• Internal
• protected-internal
• public
www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Private Access Modifier

• Objects that implement private access modifier are accessible only


inside a class or a structure. As a result, we can’t access them outside
the class they are created:

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Public Access Modifier


Objects that implement public access modifier are accessible from
everywhere in our project. Therefore, there are no accessibility
restrictions:

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Protected Access Modifier


The protected keyword implies that the object is accessible inside the
class and in all classes that derive from that class.

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Internal Access Modifier


The internal keyword specifies that the object is accessible only inside
its own assembly but not in other assemblies:

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Protected Internal Access Modifier

The protected internal access modifier is a combination of protected


and internal. As a result, we can access the protected internal member
only in the same assembly or in a derived class in other assemblies
(projects):

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

Access Modifiers Chart

www.cambridge.edu.in

www.cambridge.edu.in
#Vision2025

END
www.cambridge.edu.in

www.cambridge.edu.in

You might also like