简体   繁体   中英

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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