继承通用接口c#

时间:2017-01-17 19:47:12

标签: c# interface

我希望在一个接口中有一个泛型类型方法,该接口由两个具有特定类型的类实现。这是界面:

public interface IInterface
{
    IEnumerable<T> ExecStoredProc(string x, DateTime date,
             int y, string  statistics );
}

这两个类:

public class Class1 : Iinterface
{
    IEnumerable<Class1Type> ExecStoredProc(string x, DateTime date,
             int y, string  statistics );
}

public class Class2: Iinterface
{
    IEnumerable<Class2Type> ExecStoredProc(string x, DateTime date,
             int y, string  statistics );
}

这可能吗?

由于

1 个答案:

答案 0 :(得分:2)

您可以这样做,但界面也必须是通用的。

public interface IInterface<T>
{
    IEnumerable<T> ExecStoredProc(string x, DateTime date,
             int y, string  statistics );
}

然后实现接口的类需要实现特定类型的接口

public class Class2 : IInterface<Class2Type>