How to reverse an array (in C#) without using Array.Reverse() method?

int[] arr = {1,3,4,9,8};
for (int i = 0; i < arr.Length / 2; i++)
{
int tmp = arr[i];
arr[i] = arr[arr.Length - i - 1];
arr[arr.Length - i - 1] = tmp;
}
Console.WriteLine(string.Join(",", arr));

Leave a Reply

Your email address will not be published. Required fields are marked *