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?
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
Because "public class" is more "visible" than "internal class".
C# language has visibility protection layer that prevents this.
Internal classes can only be accessed from within the Assembly in which they are defined. When public class a inherits from an internal class in effect attempts to make the internal class public.
To avoid this encapsulate the internal class in the public class.