Section 10.5. Multiple Constraints


10.5. Multiple Constraints

A type parameter can specify multiple constraints at the same time, and only classes that meet all of the constraints can be used for that parameter. To use multiple constraints, surround the list of constraints with a set of curly braces and separate each constraint by a comma.

     Public Class WorkGroup(Of T As {New, _        Runtime.Serialization.ISerializable}) 

This statement restricts the types used for T to only those that implement the ISerializable interface and include a parameterless constructor. While you can include multiple interface constraints on a single type parameter, each type parameter can include only one class-based type constraint. It would not make sense to include two classes anyway, since Visual Basic does not allow a class to inherit from more than one base class. The New constraint can be used with either class or interface constraints.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net