简体   繁体   English

new()在此上下文中的含义是什么

[英]What does new() mean in this context

What does new() mean in the following context: new()在以下上下文中的含义是什么:

 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. 它是类型参数TEntity的约束,它指定它必须具有公共无参数构造函数。

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(); 或者,它允许你做var entity= new TEntity(); without the compiler having fits. 没有编译器适合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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