Generics where T is class implementing interface

半腔热情 提交于 2019-12-04 01:11:40

According to MSDN class means that T must be a reference type; this applies also to any class, interface, delegate, or array type.

One work around would be to require that T implements the parameter less constructor so:

where T : class, IProfile, new()

Works for me

public interface IUser
{
    int AthleteId { get; set; }
    string GivenName { get; set; }
    string FamilyName { get; set; }         
    bool IsActive { get; set; }
}

public  class DjsNameAutoSearch<Result, User> : where User : class, IUser, new()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!