What is the scope of a protected internal member variable of a class in C#?


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.

In the below example, the derived class object can access the protected internal variable.

Example

 Live Demo

using System;
class One {
   protected internal int a = 50;
   private int b;
}
class Two : One {
   public Two() {
      Console.WriteLine(this.a);
   }
}
class Demo {
   static void Main() {
      Two t = new Two();
      // allowed since it is a derived class object
      t.a = 20;
   }
}

Output

50

Updated on: 23-Jun-2020

232 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements