c#接口返回类型(不是错误)

c#接口返回类型(不是错误),c#,types,interface,return,C#,Types,Interface,Return,我得到了这样的东西: Interface IClass { (something) returnClass(); } Class Breaker: IClass { Public GIS.Breaker returnClass() { return new GIS.Breaker(); } } Class Conductor: IClass { Public GIS.Conductor returnClass() {

我得到了这样的东西:

Interface IClass
{
    (something) returnClass();
}

Class Breaker: IClass
{
    Public GIS.Breaker returnClass()
    {
        return new GIS.Breaker();
    }
}

Class Conductor: IClass
{
    Public GIS.Conductor returnClass()
    {
        return new GIS.Conductor();
    }
}
gis.breaker和gis.conductor都是使用dll文件导入的内置类

现在我不知道该如何处理接口…我需要它返回一个类型…不是字符串…不是双精度的…而是一个一般的类型


如何做到这一点?

断路器和导体必须实现一些公共接口,或者您可以使IClass通用

interface IClass<T>
{
    T ReturnClass();
}

class Breaker: IClass<GIS.Breaker>
{
    public GIS.Breaker ReturnClass()
    {
        return new GIS.Breaker();
    }
}

class Conductor: IClass<GIS.Conductor>
{
    public GIS.Conductor ReturnClass()
    {
        return new GIS.Conductor();
    }
}
接口类
{
T ReturnClass();
}
类别断路器:IClass
{
公共GIS.class()
{
返回新的GIS.Breaker();
}
}
类别:IClass
{
公共GIS.class()
{
返回新的GIS.Conductor();
}
}

但我认为将实例生成器和对象结合起来是个坏主意。

Um,
object
?或者让你的界面更通用?你希望人们如何使用这个?(请注意,如果您的示例代码使用正确的.NET命名约定,以及声明的适当大小写,例如,
public
而不是
public
),则会有所帮助)Sry用于代码…我在电话上…不是在pc上…请解释您的答案…我想让dznamic类型…它可以工作吗?嗯,也许可以。当然,您需要在实现中更改返回类型。但是,当你不能做好的时候,请不要问任何问题。等到你在电脑上,在那里你可以提供合适的上下文等。你的问题目前还不清楚,无法回答,因为我们不知道你的界面将如何使用。我通常会这样做……但我没时间了:(最重要的是……没有互联网……那是一个很糟糕的提问时间。你没有时间不是问一个糟糕问题的借口。