Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

Step: 1

Program to overload the generic method for printing the array in different manners Program Plan Create the namespace for defining the application Create the class for userdefined exception This class ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
60969278adb81_27015.pdf

180 KBs PDF File

Word file Icon
60969278adb81_27015.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Taxation For Business And Investment Planning 2016 Edition

Authors: Sally Jones, Shelley Rhoades Catanach

19th Edition

1259549259, 978-1259618536, 1259618536, 978-1259549250

More Books

Students also viewed these Programming questions