Multiple Inheritance in C#

No, C# does not support multiple inheritance for classes. Multiple inheritance refers to the ability of a class to inherit from more than one base class. In C#, a class can only inherit from a single base class.


C# Interview questions and answers

However, C# does support multiple inheritance through interfaces. An interface defines a contract that a class can implement, and a class can implement multiple interfaces. This allows a class to inherit behavior from multiple sources.

interface IInterface1 { void Method1(); } interface IInterface2 { void Method2(); } class MyClass : IInterface1, IInterface2 { public void Method1() { // Implementation of Method1 } public void Method2() { // Implementation of Method2 } }
multiple Inheritance in C#

In the above example, the class MyClass implements both IInterface1 and IInterface2, allowing it to inherit and provide implementations for the methods defined in both interfaces.


Although C# does not support multiple inheritance for classes, it provides the concept of interfaces to achieve similar functionality and flexibility by allowing a class to implement multiple interfaces and inherit behavior from multiple sources.