Why no multiple inheritance allowed in C#?

Hi ,

Why no multiple inheritance allowed in C#

Thanks,

Senthil,



Answer this question

Why no multiple inheritance allowed in C#?

  • Joe Zott

    A nice blogpost from Nick explanes a lot and got some sample code. Take a look at the post here.


  • cnewbie

    You can use interfaces to implement some kind of multiple inheritance (although it is not implementation inheritance).
    However, I haven't really encountered a situation yet in my 6+ years of being a software developer in where I've said 'well, now I should really use MI to tackle this problem'.
    Maybe you can elaborate a bit more on your specific problem Maybe there are other options / designs possible in where you shouldn't have to use MI ...


  • David Dilworth

    MS did not implement MI in C# because it would add a lot of complexity which would have an impact on things as generics, reflection, etc....

    Also, one of the major OO-design rules is: 'favor composition over inheritance'. As I've said before, I haven't had a situation where I really missed MI.

    This is an answer on this question, as posted on a C# FAQ by Chris Brumme:
    1. Different languages actually have different expectations for how MI works. For example, how conflicts are resolved and whether duplicate bases are merged or redundant. Before we can implement MI in the CLR, we have to do a survey of all the languages, figure out the common concepts, and decide how to express them in a language-neutral manner. We would also have to decide whether MI belongs in the CLS and what this would mean for languages that don't want this concept (presumably VB.NET, for example). Of course, that's the business we are in as a common language runtime, but we haven't got around to doing it for MI yet.

    2. The number of places where MI is truly appropriate is actually quite small. In many cases, multiple interface inheritance can get the job done instead. In other cases, you may be able to use encapsulation and delegation. If we were to add a slightly different construct, like mixins, would that actually be more powerful

    3. Multiple implementation inheritance injects a lot of complexity into the implementation. This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.[/]

  • WeeZarD

    Thanks for your reply, I just want to get clarified to know why C# allows multiple interface implementation why doesn't allow multiple class inheritance. If you gimme some sample piece of code that would be helpfull

    Thanks

    Senthil


  • ExCon

    You should take a look at this article at C# Corner.

  • A. Dachauer

    Thanks Frederik
  • KayJay

    Thank you Sir
  • Why no multiple inheritance allowed in C#?