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.3. Generic Method Implementation

The overloaded methods of Fig. 25.1 can be more compactly and conveniently coded using a single generic method. You can write a single generic method declaration that can be called at different times with arguments of different types. Based on the types of the arguments passed to the generic method, the compiler handles each method call appropriately.

Figure 25.3 reimplements the application of Fig. 25.1 using a single generic Print-Array method (lines 19–25). Note that the PrintArray method calls in lines 11, 13 and 15 are identical to those in Fig. 25.1, the outputs of the two applications are identical and the code in Fig. 25.3 is 18 lines shorter than the code in Fig.25.1. As illustrated in Fig. 25.3, generics ...

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