2017-01-17 69 views
-1

我想要在由具有特定類型的兩個類實現的接口內具有泛型類型方法。這是接口:繼承自通用接口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); 
} 

這可能嗎?

謝謝

+0

爲什麼向下票呢? – user1647160

回答

1

你可以做到這一點,但接口也必須是通用的。

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

然後類實現接口需要實現的接口,用於特定類型

public class Class2 : IInterface<Class2Type> 
+1

非常感謝。這工作。 – user1647160