See this code:
internal class c
{
private int d;
}
public class a : c
{
private int b;
}
Why can I not inherit a public class from an internal class? Why does the compiler have this behavior?
Because the public class would be visible outside your current assembly, while the internal one isn't. When deriving from a class you can only restrict visibility further, because in your case it would make the implementation of c
available to consumers outside your assembly which kind of defeats the purpose of making the class internal in the first place.
You can use composition instead of inheritance, though.
C# design principle. Derived class should atleast have same accessibility as the parent class. In your case it is not hence not allowed. Take a look at Eric Lippert's view on this deriving public class from an internal class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With