[英]Implement Generic Interface
I have a generic interface, looking like this 我有一个通用的界面,看起来像这样
public interface IDataReader<T> where T:class
{
IQueryable<T> ReadFile(DataTable table);
}
and I want to create a class that implement this interface. 我想创建一个实现此接口的类。 Is it possible that we actually create a class that using real class instead of generic like the interface ?
我们是否有可能实际上使用真实类而不是像接口那样使用泛型来创建一个类?
public class CustomnReader<Person> : IDataReader<T>
Thank you 谢谢
You must do like this 你一定要这样
public class CustomnReader<Person> : IDataReader<T> // <- Here you must give an exact class
public class CustomnReader<Person> : IDataReader<Person> // Like this
or you can do 或者你可以做
public class CustomnReader<T> : IDataReader<T> where T : class // <- Here create and give a type when creating an object
CustomerReader<Person> cr = new CustomerReader<Person>;
Thanks Yuval and Suren, 感谢Yuval和Suren,
I end up using 我最终使用
public class CustomnReader : IDataReader<Person>
it looks like it can work as for now. 看起来它现在可以正常工作。
Thank you 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.