#620 – Inherit from a Class In A Different Assembly
July 5, 2012 Leave a comment
You can create a new class that inherits from a class that exists in another assembly (e.g. in a class library), as long as the parent class is public (and not sealed).
Let’s assume that someone gives you a copy of DogLibrary.dll, which includes two classes–a Dog class, which is defined as public and a DogMath class, which is defined as internal.
In another program, you can inherit from the Dog class, as long as you add a reference to the DogLibrary assembly.
You inherit from the Dog class just like you inherit from a class within your own program.
public class Program { public class CrazyDog : Dog { public override void Bark() { Console.WriteLine("Grrrowfffpermuckledoodleweeeheehee!"); } } static void Main() { CrazyDog myDog = new CrazyDog(); myDog.Bark(); } }