A colleague and I are having a bit of an argument over multiple inheritance. I\'m saying it\'s not supported and he\'s saying it is. So, I thought that I\'d ask the brainy
Actually, it depends on your definition of inheritance:
This is not what is usually meant by the term "inheritance", but it is also not entirely unreasonable to define it this way.
Like Java (which is what C# was indirectly derived from), C# does not support multiple inhertance.
Which is to say that class data (member variables and properties) can only be inherited from a single parent base class. Class behavior (member methods), on the other hand, can be inherited from multiple parent base interfaces.
Some experts, notably Bertrand Meyer (considered by some to be one of the fathers of object-oreiented programming), think that this disqualifies C# (and Java, and all the rest) from being a "true" object-oriented language.
C# does not support multiple inheritance built in.
For adding multiple inheritance to languages that does not support it, You can use twin design pattern
In generally, you can’t do it.
Consider these interfaces and classes:
public class A { }
public class B { }
public class C { }
public interface IA { }
public interface IB { }
You can inherit multiple interfaces:
class A : B, IA, IB {
// Inherits any single base class, plus multiple interfaces.
}
But you can’t inherit multiple classes:
class A : B, C, IA, IB {
// Inherits multiple base classes, plus multiple interfaces.
}
C# 3.5 or below does not support the multiple inheritance, but C# 4.0 could do this by using, as I remembered, Dynamics.
As an additional suggestion to what has been suggested, another clever way to provide functionality similar to multiple inheritance is implement multiple interfaces BUT then to provide extension methods on these interfaces. This is called mixins. It's not a real solution but it sometimes handles the issues that would prompt you to want to perform multiple inheritance.