Wednesday, 27 December 2017

Is c# support multiple inheritance?

No, c# does not support multiple inheritance of classes. To achieve multiple inheritance can go for Interface.

Exp -

public class A { }    
public class B { }
public class C { }
public class D { }
public class E { }

public interface IA { }
public interface IB { }
public interface ID{ }
public interface IE { }
C# does not support multiple inheritance of classes, but you are permitted to inherit/implement any number of interfaces.
This is illegal (B, C, D & E are all classes)
class A : B, C, D, E
{
}
This is legal (IB, IC, ID & IE are all interfaces)
class A : IB, IC, ID, IE
{
}
This is legal (B is a class, IC, ID & IE are interfaces)
class A : B, IC, ID, IE
{
}

No comments:

Post a Comment