Why C# does not support multiple inheritance?

Posted by Jalpesh P. Vadgama on ASP.net Weblogs See other posts from ASP.net Weblogs or by Jalpesh P. Vadgama
Published on Fri, 22 Jun 2012 03:26:00 GMT Indexed on 2012/06/22 9:16 UTC
Read the original article Hit count: 346

Filed under:
|

Yesterday, One of my friend Dharmendra ask me that why C# does not support multiple inheritance. This is question most of the people ask every time. So I thought it will be good to write a blog post about it. So why it does not support multiple inheritance?

I tried to dig into the problem and I have found the some of good links from C# team from Microsoft for why it’s not supported in it. Following is a link for it.

http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/85562.aspx

Also, I was giving some of the example to my friend Dharmendra where multiple inheritance can be a problem.The problem is called the diamond problem. Let me explain a bit. If you have class that is inherited from the more then one classes and If two classes have same signature function then for child class object, It is impossible to call specific parent class method.

Here is the link that explains more about diamond problem.

http://en.wikipedia.org/wiki/Diamond_problem

Now of some of people could ask me then why its supporting same implementation with the interfaces. But for interface you can call that method explicitly that this is the method for the first interface and this the method for second interface. This is not possible with multiple inheritance. Following is a example how we can implement the multiple interface to a class and call the explicit method for particular interface.

Multiple Inheritance in C#

That’s it. Hope you like it. Stay tuned for more update..Till then happy programming.

Shout it

© ASP.net Weblogs or respective owner

Related posts about c#

Related posts about c#.net