Search code examples
c#inheritanceusing-directives

Inheriting from classes


In C#, how many classes can you inherit from?

When you write:

using System.Web.UI;

is that considered inheriting from a class?


Solution

  • A using directive:

    using X.Y.Z;
    

    only means that if an identifier isn't in the local namespace, the namespace X.Y.Z will be searched for that identifier as well. This allows you to have somewhat terser code, so you don't have to do System.IO.Path.Combine() if you have using System.IO.Path, for instance. I don't believe there is a limit on how many using statements you can have.

    C# does not allow multiple inheritance -- you can only inherit from one class. However, you can implement as many interfaces as you'd like.