C# - Multiple class inheritance using interfaces

We have two interfaces IA, IB, and two classes implementing them.
If we want to have another class implement both IA, IB. Instead of writing repetitive code, we can simply reuse A, B.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
interface IA
{
void AMethod();
}
class A: IA
{
public void AMethod()
{
//...
}
}

interface IB
{
void BMethod();
}
class B: IB
{
public void BMethod()
{
//...
}
}

It’d be like:

1
2
3
4
5
6
7
8
9
10
11
12
13
class AB: IA, IB
{
A a = new A();
B b = new B();
public void AMethod()
{
a.AMethod();
}
public void BMethod()
{
b.BMethod();
}
}