Multiple Inheritance in C#

C# supports single inheritance, however they do support multiple 'interface' inheritance:

Here's a sample demonstrating the same:


//Single Inheritance

public class A
{
public A() { }
}

public class B : A
{
public B() { }
}


//Multiple Interface Inheritance

interface IComparable
{
int CompareTo(object obj);
}

interface ISomethingElse
{
int EqualTo();
}


public class Z : IComparable, ISomethingElse
{
public int CompareTo(object obj)
{
// implementation code goes here
}


public int EqualTo()
{
// implementation code goes here
}
}

Leave a Reply