[英]Inheriting from a generic interface c#
I want to have a generic type method within an interface that is implemented by two classes that have specific types. 我想在一个接口中有一个通用类型方法,该接口由具有特定类型的两个类实现。 This is the interface: 这是接口:
public interface IInterface
{
IEnumerable<T> ExecStoredProc(string x, DateTime date,
int y, string statistics );
}
The two classes: 这两个类:
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 );
}
Is this possible? 这可能吗?
Thanks 谢谢
You can do this but the interface also has to be generic. 您可以执行此操作,但接口也必须是通用的。
public interface IInterface<T>
{
IEnumerable<T> ExecStoredProc(string x, DateTime date,
int y, string statistics );
}
And then classes implementing the interface need to implement the interface for specific type 然后实现接口的类需要为特定类型实现接口
public class Class2 : IInterface<Class2Type>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.