As Jon said, you need to call DisplayArray(A);
before mutating int[] A = { 3, -12, 6, 9, -7, -13, 19, 35, -8, -11, 15, 27,-1 };
.
Like this:
int[] A = { 3, -12, 6, 9, -7, -13, 19, 35, -8, -11, 15, 27,-1 };
Console.WriteLine("The array I want to change:");
DisplayArray(A);
Console.WriteLine("\n=====================\n");
Console.WriteLine("Swapping first and last element");
SwapFirstAndLast(A);
DisplayArray(A);
//pause
Console.ReadLine();
Common mistake for all beginner and professional programmers :). Next time, just step through the main
method line by line and say to yourself what this particular line of code does. If it's inconsistent to what you want to do, then now you notice there is an issue :).
Alternatively you can use two arrays, say A
which is your input array, assign A
as B
, and use SwapFirstAndLast(B)
, so you have both the mutated and non-mutated array for use.