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

CsharpProgrammingServer Side Programming

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
raja
Published on 18-Sep-2018 08:03:17
Advertisements