Why doesn't C# have multiple inheritance?

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?

Because C# didn't want C# to have multiple inheritance.

Deeper answer: Because .NET team decided so.

Even deeper answer: Because of Common Language Specification.

Even even deeper answer: You know C# can have it. Question actually means why Visual C# or the C# that follows CLS doesn't have it?

Okay. Here is the lame answer:

Because it might create situations where class B and class C inherits from class A; and class D inherits from class B and class C.


    class A { }
    class B: A { }
    class C: A { }
    class D: B, C { }

This creates a diamond inheritance problem.

Note: If you believe this shit, then you must be from India.

Funny story: A startup from Pune interviewed me and offered me this bullshit as answer. Don't take bullshit for an answer.

Super Note: Just think about it If goal of OO is to move towards real world as much as possible, then at least bi-classical-inheritance is required. Since, in real world, it takes two to come up with an offspring.

But, this will make verification of generated machine code a little bit dubious.

So the answers are:

  • Using multiple inheritance will be unverifiable.
  • CLS will be violated.
  • Due to CLS violation interop between multiple languages under .net (at least) won't be possible.

Be on offense by:

  • Asking If such a thing really is a problem, then why multiple interfacing?
  • Telling It's entirely possible to do MI in C#, using interfaces, composition, and delegation.
  • Asking What happens in case of multiple interfacing and why isn't that a solution for multiple inheritance?
  • Asking In case of multiple inheritance language could have decided hierarichical base-most class.

Reference