C# Class Access Modifiers

In this article we will discuss about what kind of Access modifiers can be used with C# Classes and how they work.
  • 2851

Access modifier defines the accessibility level of the class. It defines the scope of accessing the class in the application. The Access modifiers of the Class are used to set the accessibility level of the class. We can only use one of these modifiers in a class declaration. We can use three access modifiers with the Class i.e. public, private, internal.

These are as follows:

Access Modifier Purpose
Internal This is the default access modifier of the class. It means class can be accessed only within the same assembly in which it resides. It cannot be accessed outside the Assembly or the application.
Public Public members  are not restricted to anyone. Anyone who can see them can also access it. the Public Class can be accessed inside the same assembly as well as outside the same assembly.
Private Private class cannot be accessed by anyone and we can have a private Class within another Class and it will work like private member of the Class.
Protected Protected visibility of the class is used to define the Accessibility to the derived class which means protected classes can be accessed by its derived classes.

We cannot declare any outer class as private, protected or protected internal in C# since the access modifier for outer level classes defines their visibility in relation to other assemblies. Specifically visible within the assembly only or outside the assembly. When we declare the inner class as Protected or Private it treats as the Outer Class member.

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2018 DotNetHeaven. All rights reserved.