I understand why I should use ref
when writing a function to swap two values, but I don't know how to use the keyword on an entire array. It sounds silly, but I have tried sticking the keyword everywhere I could possibly think of (e.g. before the parameter, before the variables, etc...) but I still get the following error:
Error 1 An object reference is required for the non-static field, method, or property 'Swap.Program.swapRotations(int[])'
Here is what I have done so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Swap
{
class Program
{
static void Main(string[] args)
{
int[] A = {0, 1, 2, 3, 4, 5, 6, 7};
swapRotations(A);
for (int i = 0; i < A.Length; i++)
Console.WriteLine(A[i]);
Console.WriteLine("\nPress any key ...");
Console.ReadKey();
}
private void swapRotations(int[] intArray)
{
int bone1Rot = intArray[3];
int bone2Rot = intArray[5];
// Make the swap.
int temp = bone1Rot;
bone1Rot = bone2Rot;
bone2Rot = temp;
}
}
}