So I was wondering why there isn’t multiple inheritance in C#,- to be honest I actually never questioned that before. With the whole Mammal inherits from Animal examples in books, it seemed logical. But I have two parents, and I’ve inherited from both of them. How come we don’t do this in C#?
You can give this one a long answer, or a short one. I’ll go for the short one here, because I am quite sure I’ll get some good comments on this one.
And by the way, I LOVE the comments, I read all of them,- and I still get super excited when I get an email that a new comment has been made. It makes my day, short or long- I am very very happy for the time and effort people put to add something very valuable to this site (and my life) – a conversation! Me like a lot!
So the answer: (short version of this one)
1. Different implementations of MI across languages makes it a challenge to make a language-neutral implementation.
2. Interfaces can be used instead, which makes MI a bit redundant.
3. MI adds complexity in regards to casting, reflection and so on.
Plus a little quote from Stackoverflow: (funny description of the problem)
Multiple inheritance of implementation is what is not allowed.
The problem is that the compiler/runtime cannot figure out what to do if you have a Cowboy and an Artist class, both with implementations for the draw() method, and then you try to create a new CowboyArtist type. What happens when you call the draw() method? Is someone lying dead in the street, or do you have a lovely watercolor?
I believe it’s called the double diamond inheritance problem.