需要C#中的多重继承功能.我究竟做错了什么? [英] Need multiple inheritance functionality in C#. What am I doing wrong?

查看:79
本文介绍了需要C#中的多重继承功能.我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class UDPClient
{
}

class LargeSimulator
{
}

class RemoteLargeSimulatorClient : UDPClient, LargeSimulator
{
}

俗话说,如果您需要多重继承,那么您的设计就关闭了.

The saying goes, if you need multiple inheritance, your design is off.

如何在C#中完成而无需执行任何操作?

How would I get this done in C# without having to implement anything?

推荐答案

您只能从C#中的单个基类中固有.但是,您可以根据需要实现任意数量的接口.将此事实与扩展方法的出现结合起来,您会遇到一个(棘手的)解决方法.

You can only inherent from a single base class in C#. However, you can implement as many Interfaces as you'd like. Combine this fact with the advent of Extension Methods and you have a (hacky) work-around.

这篇关于需要C#中的多重继承功能.我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆