繁体   English   中英

从通用接口C#继承

[英]Inheriting from a generic interface c#

我想在一个接口中有一个通用类型方法,该接口由具有特定类型的两个类实现。 这是接口:

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 );
}

这可能吗?

谢谢

您可以执行此操作,但接口也必须是通用的。

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

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

public class Class2 : IInterface<Class2Type>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM