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()
The where clause in a generic definition specifies constraints on the types that are used as arguments for type parameters in a generic type, method, delegate, or local function. Constraints can specify interfaces, base classes, or require a generic type to be a reference, value, or unmanaged type.
Declaring Classes Classes are declared by using the class keyword followed by a unique identifier, as shown in the following example: C# Copy. //[access modifier] - [class] - [identifier] public class Customer { // Fields, properties, methods and events go here... } The class keyword is preceded by the access level.
A class defines the kinds of data and the functionality their objects will have. A class enables you to create your custom types by grouping variables of other types, methods, and events. In C#, a class can be defined by using the class keyword.
It's a type constraint on T , specifying that it must be a class. The where clause can be used to specify other type constraints, e.g.: where T : struct // T must be a struct where T : new() // T must have a default parameterless constructor where T : IComparable // T must implement the IComparable interface.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With