2

What does new() mean in the following context:

 public interface ISpecification<TEntity>
        where TEntity : class,new()
John Saunders
  • 159,224
  • 26
  • 237
  • 393
user282807
  • 905
  • 3
  • 13
  • 25

2 Answers2

6

It is a constraint on the type parameter TEntity that specifies that it must have a public parameterless constructor.

See Constraints on Type Parameters.

Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434
4

It means you can construct the class with a parameterless public constructor. Or, it lets you do var entity= new TEntity(); without the compiler having fits.

Wyatt Barnett
  • 15,500
  • 3
  • 32
  • 52