问题
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