Protected in C#

Two possibilities:
1. Protected member that is in the same class.
2. We can access the 'Protected' member only if the class inherits from a class from where the member is defined.


Case 1:
using System;
using System.IO;

namespace forgetCode
{
    class program1
    {
        protected string name = "Forget Code";


        static void Main(string[] args)
        {

            program1 obj = new program1();
            Console.WriteLine(obj.name);


        }
    }
}


Output:
Forget Code


Case 2:
using System;
using System.IO;

namespace forgetCode
{
    class program1
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Example for Protected :");
            program3 obj = new program3();

        }
    }

    class program2
    {
        
       protected string name = "Forget Code";
    
    }

    class program3:program2
    {
        public program3()
        {
            Console.WriteLine(name);
        }
        
           
    }
}



Output:
Example for Protected :
Forget Code

..