C# Protected Internal Access Specifiers

In this chapter you will learn:
  • What is protected internal access specifier?
  • What is the boundary of protected internal access specifier?
  • How to use protected internal access specifier in C# programming?

The protected internal access specifier allows its members to be accessed in derived class, containing class or classes within same application. However, this access specifier rarely used in C# programming but it becomes important while implementing inheritance.

 

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Protected_Internal
{
    class access
    {
        // 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)
        {
            access ac = new access();
            Console.Write("Enter your name:\t");
            // Accepting value in protected internal variable
            ac.name = Console.ReadLine();
            ac.print();
            Console.ReadLine();
        }
    }
}

Output


Enter your name:     Steven Clark
My name is Steven Clark __

Summary

In this chapter you learned about protected internal access specifier in C#. In next chapter you will learn get set modifier in C#.

 

Share your thought