Question: Overload generic method DisplayArray of Fig so that it takes two additional int arguments: lowlndex and highlndex. A call to this method displays only the

Overload generic method DisplayArray of Fig so that it takes two additional int arguments: lowlndex and highlndex. A call to this method displays only the designated portion of the array. Validate lowlndex and highlndex. If either is out of range, or if highlndex is less than or equal to lowlndex, the overloaded DisplayArray method should throw an InvalidlndexException; otherwise, DisplayArray should return the number of elements displayed. Then modify Main to exercise both versions of DisplayArray on arrays intArray, double-Array and charArray. Test all capabilities of both versions of DisplayArray.

Fig Using a generic method to display arrays of different types. 1// Fig. 20.3: GenericMethod.cs 2 // Using overloaded methods to display arrays

Fig Using a generic method to display arrays of different types. 1 // Fig. 20.3: GenericMethod.cs 2 // Using overloaded methods to display arrays of different types. 3 using System; using 4 5 6 7 8 12 13 14 15 16 17 18 19 20 21 22 System.Collections.Generic; class Generic Method { public 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', '0' }; Console.WriteLine("Array intArray contains:" ); DisplayArray( intArray); // pass an int array argument Console.WriteLine("Array doubleArray contains:"); Display Array( doubleArray ); // pass a double array argument Console.WriteLine("Array charArray contains:" ); Display Array( charArray ); // pass a char array argument } // end Main 23 24 25 // output array of all types private static void DisplayArray ( T[] inputArray ) { foreach (T element in inputArray ) Console.Write( element + " "); 26 27 28 29 Console.WriteLine(""); } // end method Display Array 31 } // end class Generic Method 30 Array intArray contains: 1 2 3 4 5 6 Array doubleArray contains: 1.1 2.2 3.3 4.4 5.5 6.6 7.7 Array charArray contains: HELLO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem we need to overload the DisplayArray method to accept two ad... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

60969278adb81_27015.pdf

180 KBs PDF File

Word file Icon

60969278adb81_27015.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!