Multiple Inheritance in C#

Feb 9, 2010 Posted by Lara Kannan
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
}
}

Share
Labels: ,

Post a Comment