O'Reilly logo

Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition by Harvey M. Deitel - Deitel & Associates, Inc., Paul J. Deitel - Deitel & Associates, Inc.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

25.2. Motivation for Generic Methods

Overloaded methods are often used to perform similar operations on different types of data. To motivate the concepte of generic methods, let’s begin with an example (Fig. 25.1) that contains three overloaded PrintArray methods (lines 19–25, 28–34 and 37–43). These methods display the elements of an Integer array, a Double array and a Char array, respectively. In Section 25.3, we reimplement this program more concisely and elegantly using a single generic method.

Figure 25.1. Displaying arrays of different types using overloaded methods
					1
					' Fig. 25.1: OverloadedMethods.vb
					2
					' Using overloaded methods to print arrays of different types.
					3
					Module OverloadedMethods
 4
					Sub Main()
 5
					' create arrays of Integer, Double ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required