July 2015
Intermediate to advanced
1300 pages
87h 27m
English
With constraints, you can control the behavior of generics and provide additional functionalities and limit the implementation to specific data types. Let’s begin by understanding constraints on methods.
Imagine you want the ability to compare two items within an array. To accomplish this, you need to take advantage of the IComparable interface, and because of this, you want to require that the type argument implements the IComparable interface. The following code demonstrates this:
Public Function CompareItems(Of T As IComparable)(sourceArray() As T, index1 As Integer, index2 ...