Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C语言中派生两个抽象类#_C#_.net_C# 4.0_Interface - Fatal编程技术网

C# 如何在C语言中派生两个抽象类#

C# 如何在C语言中派生两个抽象类#,c#,.net,c#-4.0,interface,C#,.net,C# 4.0,Interface,我有应用程序结构- public abstract class a { } //defined in a.dll public abstract class b { } //defined in b.dll //Above 2 DLL reference added in main project where I want to derive both of this abstract classee like public abstract class proj : a, b { }

我有应用程序结构-

public abstract class a 
{
}
//defined in a.dll
public abstract class b
{
}
//defined in b.dll

//Above 2 DLL reference added in main project where I want to derive both of this abstract classee like

public abstract class proj : a, b
{
}
我能推导出其中任何一个,但不能同时推导出两者。所以,请指导我丢失的东西或错误的编码,我已经做了

public abstract class proj : a, b

这是办不到的。C#不允许多重继承。

不是从多个抽象类派生(这在C#中是非法的),而是从两个接口派生(根据定义是抽象的)。

不能使用C#进行多重继承。但是,您可以通过使用


C#接口只允许方法、属性、事件和索引器的签名。您必须在
proj
(MainProgram)类中定义这些的实现。

您不能同时从两个类派生。您应该改用接口

public interface IFirstInterface
{
}
public interface ISecondInterface
{
}

public abstract class Proj : IFirstInterface, ISecondInterface
{
}

现在继承自
Proj
的类仍然需要实现两个接口中定义的所有方法和属性

如果你引用你得到的错误,这是很有帮助的。例如,如果您得到错误CS1721:Class'proj'不能有多个基类:'a'和'b',那么在您的问题中引入该信息。当其他人有类似的错误时,它将更容易被发现。
public interface IFirstInterface
{
}
public interface ISecondInterface
{
}

public abstract class Proj : IFirstInterface, ISecondInterface
{
}