Home > Article > Backend Development > What is multiple inheritance in C#?
C# does not support the use of multiple inheritance, but it can be implemented using interfaces.
The following is the implementation using interface inheritance. Create two interfaces-
public interface BaseOne { void display(); } public interface BaseTwo { void display(); }
Now set up the interface like setting up a derived class,
public class ChildOne : BaseOne, BaseTwo { public void display() { Console.WriteLine("Child Class!"); } }
We will call the subclass function as shown in the following code to implement multiple inheritance in C#-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { ChildOne c = new ChildOne(); c.display(); Console.ReadKey(); } } public interface BaseOne { void display(); } public interface BaseTwo { void display(); } public class ChildOne : BaseOne, BaseTwo { public void display() { Console.WriteLine("Child Class!"); } } }
The above is the detailed content of What is multiple inheritance in C#?. For more information, please follow other related articles on the PHP Chinese website!