Why c# do not support Multiple Inheritance
-
In contrast to some "experts" here on CP, I worked with a language which supports multiple inheritance: C++ (i.e. non-managed C++). Hence I think that your question is an appropriate question, it does not deserve downvoting. Let me give you an example which shows where multiple inheritance is a pain. Imagine two base classes which have a function with the same name.
public class FirstClass
{
public virtual void DoSomething()
{
//some code
}
}and
public class SecondClass
{
public virtual void DoSomething()
{
//some other code
}
}When you create a class inheriting from both of these classes
public class CombinedClass: FirstClass, SecondClass
{
//some other code
}it inherits the
DoSomething()
method from bothFirstClass
andSecondClass
. When you callDoSomething()
on an instance ofCombinedClass
CombinedClass c = new CombinedClass();
c.DoSomething()which of the
DoSomething()
methods do you call -FirstClass.DoSomething()
orSecondClass.DoSomething()
? Other object oriented languages may offer more features which are not supported in the .Net world, e.g. inheritance of static functions and properties.I like your example and way of thinking great!!!! Thanks