Hi Everyone forgot to mention the types you should mention when specifying a constraint using where keyword the following table illustrates more -
Generic Constraint Meaning in Life
where T : struct The type parameter must have System.ValueType in its chain of inheritance.
where T : class The type parameter must not have System.ValueType in its chain of inheritance (e.g., must be a reference type).
where T : new() The type parameter must have a default constructor. This is very helpful if your generic type must create an instance of the type parameter, as you cannot assume the format of custom constructors. Note that this constraint must be listed last on a multiconstrained type.
where T : NameOfBaseClass The type parameter must be derived from the class specified by NameOfBaseClass.
where T : NameOfInterface The type parameter must implement the interface specified by NameOfInterface.Multiple interfaces can be separated as a comma-delimited list.
Program Code-

0 comments:
Post a Comment