[英]How to call method of a generic input type class
I have a class我有一堂课
public abstract class CommonService<T,U> : IService<T> where T : NameDTO where U : IRepository
{
public async Task SaveData(T editObj, int Id, short TypeId)
{
.. implementation
}
}
I have to call the method inside this class, so I am trying below method:我必须在这个类中调用该方法,所以我正在尝试以下方法:
CommonService<XYZFiltersDTO, IXYZRepository> _commonService;
await _commonService.SaveData(myObj, 23, 12);
but I am getting error at但我在
await _commonService.SaveData(myObj, 23, 12);
等待 _commonService.SaveData(myObj, 23, 12);
"use of unassigned local variable _commonService." “使用未分配的局部变量 _commonService。”
Like others have said, you can't create an instance of abstract class.就像其他人所说的那样,您不能创建抽象类的实例。 You must create a class that implements it.
您必须创建一个实现它的类。
https://docs.microsoft.com/en-us/visualstudio/ide/reference/implement-abstract-class?view=vs-2017 https://docs.microsoft.com/en-us/visualstudio/ide/reference/implement-abstract-class?view=vs-2017
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.