May 2010
Intermediate to advanced
1272 pages
61h 18m
English
With constraints you can control Generics’ behavior, and both 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:

Notice how the As clause in the method argument requires the type to implement the IComparable interface. If the type ...
Read now
Unlock full access