// Fig. 26.3: GenericMethod.cs // Using overloaded methods to print arrays of different types. using System; using System.Collections.Generic; class GenericMethod { static void Main( string[] args ) { // create arrays of int, double and char int[] intArray = { 1, 2, 3, 4, 5, 6 }; double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 }; char[] charArray = { 'H', 'E', 'L', 'L', 'O' }; Console.WriteLine( "Array intArray contains:" ); PrintArray( intArray ); // pass an int array argument Console.WriteLine( "Array doubleArray contains:" ); PrintArray( doubleArray ); // pass a double array argument Console.WriteLine( "Array charArray contains:" ); PrintArray( charArray ); // pass a char array argument } // end Main // output array of all types static void PrintArray< E >( E[] inputArray ) { foreach ( E element in inputArray ) Console.Write( element + " " ); Console.WriteLine( "\n" ); } // end method PrintArray } // end class GenericMethod /************************************************************************** * (C) Copyright 1992-2006 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/