“在哪里" C Sharp中的类声明中的关键字 [英] "where" keyword in class declaration in c sharp

查看:119
本文介绍了“在哪里" C Sharp中的类声明中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以在下面的类声明中帮助我使用where TEntity : class, IEntity, new()行.

Could anyone help me with the line where TEntity : class, IEntity, new() in the following class declaration.

public abstract class BaseEntityManager<TEntity>
        where TEntity : class, IEntity, new()

推荐答案

where TEntity : ...将约束应用于通用参数TEntity.在这种情况下,约束为:

where TEntity : ... applies constraints to the generic parameter TEntity. In this case, the constraints are:

class:TEntity的参数必须是引用类型
IEntity:参数必须是IEntity接口或必须实现IEntity接口
new():参数必须具有公共的无参数构造函数

class: The argument to TEntity must be a reference type
IEntity: The argument must be or implement the IEntity interface
new(): The argument must have a public parameterless constructor

来自 http://msdn.microsoft.com/en-us/library /d5x73970.aspx

这篇关于“在哪里" C Sharp中的类声明中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆