Answered step by step
Verified Expert Solution
Link Copied!

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(ref T a, ref T b)

  • 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(ref a, ref b);

  • 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

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

5. A review of the key behaviors is included.

Answered: 1 week ago

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago