Tag: 多重inheritance

通过引用传递:多个接口的子节点

将实现多个接口的对象传递给只需要其中一个接口的函数时,我遇到了构建错误。 我正在开发一个通讯包。 该软件包有一个Receiver类和一个Sender类。 Receiver类使用通知接口Receive_Notifier(函数对象)来处理通知。 同样,Sender类使用通知接口Send_Notifier来处理通知。 interface Send_Notifier { void sending_text(string text); } interface Receive_Notifier { void raw_text_received(string raw_text); } class Sender { Send_Notifier m_notifier = null; public Sender(ref Send_Notifier notifier) { m_notifier = notifier; } public void send(string text) { m_notifier.sending_text(text); return; } } class Receiver { Receive_Notifier m_notifier = null; public Sender(ref Receive_Notifier notifier) […]

多个派生抽象类?

我必须创建一个课程管理系统,其中包括课程类别: Cooking, sewing and writing courses cooking和writing每个都有2道菜(意大利,海鲜,创意写作和商业写作)。 这会创建派生的抽象: abstract course -> abstract cooking -> concrete seafood 抽象的烹饪和写作有共同的领域和一些常用的方法,但是它们也有抽象的方法在基类中是抽象的。 这可以在C#中完成吗? 如果我使派生的抽象类方法抽象Visual Studio说他们隐藏基类抽象然后具体的类方法有错误说基类必须是抽象的(它必须但不能注册)。 我找了答案。 我知道单inheritance在C#中使用,但inheritance带有链。 什么是最好的答案? 这是一个代码片段 – 我希望它澄清了问题: public abstract class Course { public abstract void AddStudent(StudentName sn, int f); public abstract decimal CalculateIncome(); } public abstract class WritingCourse : Course { public void AddStudent(StudentName sn, int […]

当我真的需要从两个类inheritance时如何处理CS1721?

在我的C#代码中,我想要一个inheritance自System.MarshalByRefObject和System.Security.Principal.GenericIndentity类的CustomIdentity类。 但是当我尝试编写这样的inheritance时,C#会反对CS1721错误,说我不能直接从多个类inheritance。 现在在这种情况下,很容易克服这一点 – 我将inheritanceIIdentity ,添加GenericIdentity成员变量并通过该成员变量重新实现所有IIdentity方法。 但是如果我想用两大类方法inheritance两个类,我该怎么做?

为什么C#允许通过接口扩展方法而不是类来进行多重inheritance?

我已经检查了其他问题,但令人惊讶的是,这个问题似乎没有被问到。 使用Extension方法,接口提供有限但真正的实现多重inheritance。 这带来了Diamond问题,与基于类的多inheritance相同。 为什么这比基于类的多重inheritance更好或更可接受,这么多人似乎觉得这么可怕? 它实际上似乎是一种更糟糕的实现多重inheritance的方式,因为扩展方法不能进入接口本身,甚至不能进入实现接口的类,但最终可能分散在多个静态实用程序类中。 Eric Lippert在他的博客(2009年10月5日上午9:29)似乎对扩展属性的概念持开放态度,甚至提到了扩展事件,扩展操作符,扩展构造函数(也称为“工厂模式”)的可能性。 因此可以进一步扩展通过接口的实现。 编辑:为了阐明一个类是否inheritance了两个接口,这两个接口都具有相同名称和类型参数的扩展方法,如果调用方法而不显式命名接口,则会产生编译错误。 考虑到这一点,我错了,因为这不是钻石问题。 然而,考虑到这一点提出了一个问题,即钻石问题与其他歧义相比有多重要? 为什么Diamond问题难以解决,它是否可以通过简单的编译错误来获取,就像接口扩展方法类冲突并且不能隐式解析一样? 即使在基于类的多重inheritance中,也可能存在非基于Diamond的成员签名冲突。

C#中的多重inheritance

当我作为C#开发人员工作时,我知道我们可以通过使用Interface实现multiple inheritance 。 任何人都可以提供链接或代码,了解如何使用C#实现multiple inheritance 。 我想要使​​用Interface在C#实现多重inheritance的代码。 提前致谢。

使用“相同名称”属性实现2个接口

这似乎是一个合理的(也许是简单的?)场景,但您将如何执行以下操作: 可以说我有2个接口: Interface ISimpleInterface string ErrorMsg { get; } End Interface Interface IExtendedInterface string ErrorMsg { get; set; } string SomeOtherProperty { get; set; } End Interface 我想要一个类来实现这两个接口: Public Class Foo Implements ISimpleInterface, IExtendedInterface 如果每个接口具有不同的访问级别,如何在类中定义ErrorMsg属性? 以下是我想知道的情况:我正在使用伪造的MVC架构编写UserControl,其中UserControl将扩展接口暴露给它的Controller,并将Simple接口暴露给控件的使用者。 顺便说一句,在VB.NET中实现这一点(vb中的任何建议的synatx将不胜感激)。

dotnet不支持多重inheritance。 但多个接口支持?

可能重复: C#中的多重inheritance dotnet不支持多重inheritance。 但是多个接口支持。 为什么会出现这种行为。 任何具体原因??

c#多重inheritance

我想在C#中实现这一点 (伪代码) class A; class B : A; class C : A, B; … A ac = (A)c; … B bc = (B)c; 这可能吗?

如何在C#中模拟多重inheritance

我怎样才能做到这一点: Class A : DependencyObject {} Class B : DependencyObject {} Class C : A , B {}