简体   繁体   中英

What does new() mean in this context

What does new() mean in the following context:

 public interface ISpecification<TEntity>
        where TEntity : class,new()

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

See Constraints on Type Parameters .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM