Alexey
Alexey

Reputation: 464

C# code confusion of where clause

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

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

Upvotes: 8

Views: 445

Answers (1)

Femaref
Femaref

Reputation: 61497

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

Upvotes: 15

Related Questions