ประการแรก ประกาศและเริ่มต้นอาร์เรย์หนึ่งมิติ
int[] arr = { 35, 12, 66, 90, 34, 2, 64 }; ตอนนี้ ใช้สิ่งต่อไปนี้เพื่อย้อนกลับ -
Array.Reverse(arr);
ต่อไปนี้เป็นรหัสที่สมบูรณ์เพื่อย้อนกลับอาร์เรย์หนึ่งมิติ
ตัวอย่าง
using System;
class Demo {
static void Main() {
int[] arr = { 76, 12, 66, 90, 34, 2, 64 };
// Initial Array
Console.WriteLine("Original Array= ");
foreach (int i in arr) {
Console.WriteLine(i);
}
// Reverse Array
Array.Reverse(arr);
Console.WriteLine("Reversed Array= ");
foreach (int j in arr) {
Console.WriteLine(j);
}
Console.ReadLine();
}
} ผลลัพธ์
Original Array= 76 12 66 90 34 2 64 Reversed Array= 64 2 34 90 66 12 76