[ACCEPTED]-where" keyword in class declaration in c sharp-generics

Accepted answer
Score: 32

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

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

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

Score: 5

The where keyword after the class declaration 7 restrict what type the generic TEntity could be. In 6 this case TEntity must be a class (meaning it can't 5 be a value type like int or DateTime), and it must implement 4 the interface IEntity. The new() constraint indicates 3 that methods inside this class have the 2 ability to call the default constructor 1 of the generic class represented by TEntity (e.g. new TEntity())

Score: 0

Where is a generic type constraint. That 4 lines reads that the type TEntity must be 3 a reference type as opposed to a value type, must 2 implement the interface IEntity and it must 1 have a constructor that takes no parameters.

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

More Related questions