Question: 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
Get step-by-step solutions from verified subject matter experts
