I wrote the following code:
public class A
{
protected string Howdy = "Howdy!";
}
public class B : A
{
public void CallHowdy()
{
A a = new A();
Console.WriteLine(a.Howdy);
}
}
Now, in VS2010
it results in the following compilation error:
Cannot access protected member 'A.a' via a qualifier of type 'A'; the qualifier must be of type 'B' (or derived from it).
This seems quite illogical to me - why can't I access the protected
field of the class instance from a method of the class, which is derived from it?
So, why does this happen?
Found a strict answer - http://blogs.msdn.com/b/ericlippert/archive/2005/11/09/491031.aspx