int[] arr = { 2, 4, 6, 8, 9 };
int[] arr1 = ReverseToNewArray(arr);
new int[] { 1, 2, 3, 3, 2, 1 },
new int[] { 1, 2, 3, 2, 1 },
new int[] { 1, 2, 3, 3, 2 }
foreach (var test in testArrays)
Console.WriteLine(IsPalindrome1(test));
Console.WriteLine(IsPalindrome2(test));
static void PrintArray(int[] array)
Console.WriteLine(string.Join(" ", array));
static void ReverseInPlace(int[] array)
for (int i = 0, j = array.Length - 1; i < j; i++, j--)
static int[] ReverseToNewArray(int[] array)
int[] result = new int[array.Length];
for (int i = 0; i < array.Length; i++)
result[i] = array[array.Length - 1 - i];
static bool IsPalindrome1(int[] array)
for (int i = 0, j = array.Length - 1; i < j; i++, j--)
if (array[i] != array[j])
static bool IsPalindrome2(int[] array)
int[] reversed = ReverseToNewArray(array);
for (int i = 0; i < array.Length; i++)
if (array[i] != reversed[i])