0

Since I can't have multiple base classes, I am looking forward to pass a base class as a type. Is it possible in c#?

Example:

public class MyClass : Base1<Base2> {}

public class Base1<TBase> : TBase 
{
    m1();
}

public class Base2
{
    m2();
}

This way I can access m1() and m2() from MyClass

Thanks in advance.

Vitor Durante
  • 950
  • 8
  • 25

1 Answers1

0

As others have suggested in the comments, you should probably use composition instead of trying to have multiple inheritance. In your case, that might look something like this:

public class MyClass
{
    public Base1 Base1 { get; set; }
    public Base2 Base2 { get; set; }
}

public class Base1
{
    public void m1() { }
}

public class Base2
{
    public void m2() { }
}


// use like
myClass.Base1.m1();
Community
  • 1
  • 1
Tim S.
  • 55,448
  • 7
  • 96
  • 122