简体   繁体   中英

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);

"use of unassigned local variable _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

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