Prime b

Prime b

  • NA
  • 810
  • 346.8k

Method overload

Jan 9 2012 8:00 PM
The problems

Create a console-based program whose Main() method
declares three integers named fi rstInt, middleInt, and
lastInt. Assign values to the variables, display them,
and then pass them to a method that accepts them as
reference variables, places the fi rst value in the lastInt
variable, and places the last value in the fi rstInt variable.
In the Main() method, display the three variables again,
demonstrating that their positions have been reversed.
Save the program as Reverse3.cs.

b. Create a new program named Reverse4, which contains
a method that reverses the positions of four variables.
Write a Main() method that demonstrates the method
works correctly. Save the program as Reverse4.cs.

I got the first one
            int first = 33;
            int middle = 44;
            int last = 55;

            Console.WriteLine("Before the swap the first number is {0}", first);
            Console.WriteLine("Before the swap the middle number is {0}", middle);
            Console.WriteLine("Before the swap the last number is {0}", last);
            Swap(ref first, ref middle, ref last);
            Console.WriteLine("\n============AFTER===THE===SWAP======================");
            Console.WriteLine("After the swap the first is {0}", first);
            Console.WriteLine("After the swap the middle is {0}", middle);
            Console.WriteLine("After the swap the last is {0}", last);


        }
        public static void Swap(ref int firstInt, ref int middleInt, ref int lastInt)
        {
            int temp;
            temp = firstInt;
            firstInt = lastInt;
            lastInt = temp;

But second one gives me a problem


Answers (1)