There is some mechanism to allow a class to be inherited by N classes only in C#?
You may put it and it's derived classes in a separate assembly, and declare the constructor of the base class as internal
. That way although you could inherit from it in a different assembly, but you wouldn't be able to instantiate any derived class.
No, but you can always make the constructor throw an exception if it exceeds the limit.
// can be inherited only by classes in the same assembly
public abstract class A
{
protected internal A() { }
}
// can't be inherited
public sealed class B : A
{
}
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