2

What does new() mean in the following context:

 public interface ISpecification<TEntity>
        where TEntity : class,new()
John Saunders
  • 160,644
  • 26
  • 247
  • 397
user282807
  • 905
  • 3
  • 13
  • 26

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
  • 811,555
  • 193
  • 1,581
  • 1,452
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,573
  • 3
  • 34
  • 53