user193442 user193442 - 4 months ago 8
C# Question

"where" keyword in class declaration in c sharp

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()

Answer

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

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

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