[英]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.