C# code confusion of where clause

纵饮孤独 提交于 2019-12-19 06:24:34

问题


public interface ICrudService<T> where T: Entity, new()

What is the meaning of "new()" at the end of the above code?


回答1:


new() means that T has to have a parameterless constructor.

This is a help to enable you to construct objects of type T in your generic class/method:

public T Create()
{
   return new T();
}


来源:https://stackoverflow.com/questions/5461963/c-sharp-code-confusion-of-where-clause

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!