title: Cannot access protected member?
body: <p>I am learning C#, i written the below code which is not working.</p>
  
  <p>the protected members can be accessble by inheriting the class, but in the below code it is not working can any one please tell me where i am doing mistake?</p>
  
  <pre><code>   class ProtectedDemo
  {
      protected string name;
  
      public void Print()
      {
          Console.WriteLine("Name is: {0}", name);
      }
  }
  
  class Demo : ProtectedDemo
  {
      static void Main(string[] args)
      {
          ProtectedDemo p = new ProtectedDemo();
          Console.Write("Enter your Name:");
          p.name = Console.ReadLine(); //Here i am getting the error.
          p.Print();
          Console.ReadLine();
      }
  }
  </code></pre>