Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use the example in page 69-70 to create a program that callls a class user should input variables program should create an instance of an

use the example in page 69-70 to create a program that callls a class
user should input variables
program should
create an instance of an object for the following types of shapes
circle
square
rectangle
triangle
draw the shape
image text in transcribed
image text in transcribed
DC generic. Example 2.5 Problem: Create a program that includes two methods. One will be a regular method that can print an array of strings. Try to call that method to print an array of characters. It will fail. The other method will be generic and can print any type of strings. Analysis: A generic method header will look like this: accessSpecifier reuten Type methodName In the body of the method, you must use the type parameter specified in the header (In this case "E"). The "E" is used as a placeholder. The specific type is given only when the method is called. 69 Agile Software Development with C# Book II The specific type takes the place of the "E" as the type parameter. Solution: Create a new project called Chapter 2 Generic Method with the following code inside the Main method: 1 using System; 2 namespace Chapter2GenericMethod 4 5 class Program { static void Main(string[] args) string[] astring - { "Alice", "Bob" }; char[] achar - { 'A', 'B' }; PrintMethod(aString); //PrintMethod(achar); PrintMethodGeneric(aString); PrintMethodGeneric char>(achar); Console.ReadKey(); // a method for print string array static void PrintMethod(string[] str) foreach(String s in str) Console.WriteLine(); 1/ a generic method for print anything static void PrintMethodGeneric(ED) a) foreach(Es in a) Console.WriteLine(s); Figure 2.15 Code for Example 2.5 DC generic. Example 2.5 Problem: Create a program that includes two methods. One will be a regular method that can print an array of strings. Try to call that method to print an array of characters. It will fail. The other method will be generic and can print any type of strings. Analysis: A generic method header will look like this: accessSpecifier reuten Type methodName In the body of the method, you must use the type parameter specified in the header (In this case "E"). The "E" is used as a placeholder. The specific type is given only when the method is called. 69 Agile Software Development with C# Book II The specific type takes the place of the "E" as the type parameter. Solution: Create a new project called Chapter 2 Generic Method with the following code inside the Main method: 1 using System; 2 namespace Chapter2GenericMethod 4 5 class Program { static void Main(string[] args) string[] astring - { "Alice", "Bob" }; char[] achar - { 'A', 'B' }; PrintMethod(aString); //PrintMethod(achar); PrintMethodGeneric(aString); PrintMethodGeneric char>(achar); Console.ReadKey(); // a method for print string array static void PrintMethod(string[] str) foreach(String s in str) Console.WriteLine(); 1/ a generic method for print anything static void PrintMethodGeneric(ED) a) foreach(Es in a) Console.WriteLine(s); Figure 2.15 Code for Example 2.5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

1 2 nm converted to mm

Answered: 1 week ago

Question

=+18-4 Describe the loca- tion and function of feature. detectors.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago