How to one constraint type argument passed in Generic class ?

Type argument in Generic class can be constrainted using Generic constraint.

Syntax for Generic constrint is below :

class B<T> where T: Typeconstraint
where B is Generic class
      T is type argument
      TypeConstraint is Generic Constraint
public class Stock<X> where X:IStock
This will ensure that type parameter provided for X was derived from IStock.

Leave a Reply