When we define a class generic is necessary impose one or more conditions to some parameters of type associate to the definition.
* Assume that a type inherited of a base class or implement some interface, only is possible apply to the variable of this type that is inside of the class,certain property or specify method ; In this case a parameter is replace for any kind. In this case fall from object.
The restrictions are specify using the clause where associated to the definition of the generic type.
for example public class PairSort<T> where T:struct
The restrictions that can be of five types
Heritage: The type must be inherited of a determine base class.
Interface:The type must implement a specify interface.
Reference type :The type must be a reference type(e.g. class).It used to key word "Class" in the clause where.
Value type:The type must be a value type.It used to key words "Struct" in the clause where.
Constructor:The type must have a constructor without parameters(explicit default).It used the key word new in the clause where.
Generic methods
C# allow defined only not generic type ,but also can do generic to singled method as an instance method or static method.
Swap()this is an classical example that allows to exchange the value of two values that are values type or reference type
IComparable: All the basic types implement to its manner IComparable. It allow compare instance. For example Person, it can do that this class implement it too.
IComparable force us to compare and convention of type
Generic Delegate
It is important know that some generic delegate are already present in the library of base classes of Net Framework. for example the type processing<T> already is defined with the name of Action<T>
Action delegates from the system namespace, for example action<T> and Action<T1,T2>
Encapsulates a method that has a single parameter and does not return a value
public delegate void Action<T>(T t);
Our Test Method to test this methods
The Predicate<T> delegate:Represent the method that defines a set of criteria and determines whether the specified object meets those criteria
public delegate bool Predicate<T>(T t);
The Comparison<T> delegate:Represent the method that compares two objects of the same type
public delegate int Comparison<T>(T x, T y);
Example of how implement a enumerable. I have already explained on Enumerable http://marisolca.blogspot.com/2015/06/ienumerable-interface.html .It is similarly only in this case is IEnumerable<T>
ICollection<T>:This interface implement all the generic collections. Offering basic functionality to add,delete,copy and iterator the elements of a collection.
ICollection<T> extends of IEnumerable<T> and IEnumerable
Queue<T> and Stack<T> are implement directly to ICollection<T>
Other collections inherited indirectly of ICollection<T> for example
IList<T>
IDictionary<T>Pair collection of key and value.





























