Does C# support multiple inheritance?

后端 未结 17 791
傲寒
傲寒 2020-11-27 05:34

A colleague and I are having a bit of an argument over multiple inheritance. I\'m saying it\'s not supported and he\'s saying it is. So, I thought that I\'d ask the brainy

17条回答
  •  我在风中等你
    2020-11-27 06:03

    Sorry, you cannot inherit from multiple classes. You may use interfaces or a combination of one class and interface(s), where interface(s) should follow the class name in the signature.

    interface A { }
    interface B { }
    class Base { }
    class AnotherClass { }
    

    Possible ways to inherit:

    class SomeClass : A, B { } // from multiple Interface(s)
    class SomeClass : Base, B { } // from one Class and Interface(s)
    

    This is not legal:

    class SomeClass : Base, AnotherClass { }
    

提交回复
热议问题