What is the purpose of an access specifier in C#?


To define the scope and visibility of a class member, use an access specifier.

C# supports the following access specifiers.

  • Public
  • Private
  • Protected
  • Internal
  • Protected internal

Let us learn about them one by one.

Public Access Specifier

It allows a class to expose its member variables and member functions to other functions and objects.

Private Access Specifier

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.

Protected Access Specifier

Protected access specifier allows a child class to access the member variables and member functions of its base class.

Internal Access Specifier

Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.

Protected Internal Access Specifier

The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application.

Updated on: 30-Jul-2019

359 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements