Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# code confusion of where clause

Tags:

c#

generics

where

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

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

like image 982
Alexey Avatar asked Mar 28 '11 16:03

Alexey


1 Answers

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();
}
like image 199
Femaref Avatar answered Sep 22 '22 05:09

Femaref