Protected Internal Access Modifier In C#

In this article I will explain protected internal access modifier in C#.
  • 5399

Introduction

The protected internal access specifier allows its members to be accessed in any class in the same assembly, including derived classes. However, this access specifier rarely used in C# programming but it becomes important when we want to use the concept of inheritance in the program.

The protected internal accessibility means protected OR internal, not protected AND internal.

Example

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Internal_Access_Specifier

{

    class accessmod

    {

        // String Variable declared as protected internal

        protected internal string name;

        public void print()

        {

            Console.WriteLine("\nMy name is " + name);

        }

    }

     class Program

    {

        static void Main(string[] args)

        {

            accessmod nam = new accessmod();

            Console.Write("Enter your name:  ");

            // Accepting value in internal variable

            nam.name = Console.ReadLine();

            nam.print();

            Console.ReadLine();

        }

    }

}

 

The output of following program


Clipboard151.jpg
  

© 2020 DotNetHeaven. All rights reserved.