Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a new C# Console project called Swap. Define a static generic method called swap with return type void. Give the method definition two reference
Create a new C# Console project called Swap.
- Define a static generic method called swap with return type void. Give the method definition two reference parameters called a and b.
- Note the reference to the generic
type between the function name and the parameter list.
static void swap
- In the body of the function, output the value of the two arguments passed in.
- Create a variable defined as a generic type called temp. Assign the value of a to temp.
T temp = a;
- Assign the value of b to a, then assign the value stored in temp to b. This should have swapped the values between a and b, using temp as a temporary placeholder.
- Output the value of the two variables again.
- Inside Main(), declare four variables, two integers, and two strings.
- Pass the two integers to the swap() function, including the int type declaration:
swap
- Repeat the call to swap(), this time pass the two string variables as arguments.
In both cases, the initial string displaying the values of the two parameter arguments should show the values in reverse order that you pass them.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started