Replies: 1 comment 4 replies
-
This does align with the behaviour of calling a method with the same visibility - you can't call a protected method through the base class directly: public class BaseClass
{
protected BaseClass(int value)
{
}
protected void SomeBaseMethod()
{
}
}
public class InheritingClass : BaseClass
{
protected InheritingClass(int value) : base(value)
{
}
public void Method()
{
var instance = new InheritingClass(1234);
// This is allowed
instance.SomeBaseMethod();
// This is not allowed
((BaseClass)instance).SomeBaseMethod();
}
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The compiler rejects code that calls a Protected Constructor from an inheriting class.
The workaround I need to resort to is creating a protected static method on the base class that calls the constructor.
I would expect the behaviour of calling a constructor to align with the behaviour of calling a method with the same visibility.
Beta Was this translation helpful? Give feedback.
All reactions