I am learning C#, i written the below code which is not working.
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?
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();
}
}