Reverse an array in C#
public static void
ReverseArray() { int[]
array = { 1, 2, 3, 4, 5 }; foreach (int a in
array) {
Console.WriteLine(a); }
Array.Reverse(array);
Console.WriteLine("Reversed Array : "); foreach (int value
in array) {
Console.WriteLine(value); } Console.ReadLine(); } |
public static void
ReverseArray() { int[] arr
= new int[] { 1, 2, 3, 4, 5 }; int
length = arr.Length - 1; string
strReverse = null; while
(length >= 0) {
strReverse = strReverse +
arr[length] + Environment.NewLine;
length--; }
Console.WriteLine();
Console.WriteLine("Reverse Array is " + "
" + strReverse);
Console.ReadLine(); } |
EmoticonEmoticon