Passing Delegates as Arguments

The classic example of procedural types is to pass the address of functions to sorting algorithms. As in the “Hello World!” examples, it's almost tradition to demonstrate procedural types using sort algorithms. In this section, I will demonstrate three sort algorithms that use one of two comparison functions to alternate between ascending and descending sort order.

To demonstrate passing Delegate arguments, I will guide you through the construction of SortAlgorithms.sln (contained on this book's CD-ROM, and shown in Figure 9.2). To complete the sample program, we will define a Compare Delegate that compares two integers. To perform comparisons based on a user preference of ascending or descending order, we will ...

Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.