Need multiple inheritance functionality in C#. What am I doing wrong?

后端 未结 6 1895
野性不改
野性不改 2021-01-19 09:08
class UDPClient
{
}

class LargeSimulator
{
}

class RemoteLargeSimulatorClient : UDPClient, LargeSimulator
{
}

The saying goes, if you need multip

6条回答
  •  抹茶落季
    2021-01-19 09:28

    interface ILARGESimulator
    {
    }
    
    interface IUDPClient
    {
    }
    
    class UDPClient : IUDPClient
    {
    }
    
    class LargeSimulator : ILARGESimulator
    {
    }
    
    class RemoteLargeSimulatorClient : IUDPClient, ILargeSimulator
    {
        private IUDPClient client = new UDPClient();
        private ILARGESimulator simulator = new LARGESimulator();
    
    }
    

    Unfortunately you will need to write wrapper methods to the members. Multiple inheritance in C# does not exist. You can however implement multiple interfaces.

提交回复
热议问题