CSharp · Console
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002175/array-reverse
// @nuget: Z.ExtensionMethods
using System;
public class Program
{
public static void Main()
{
int[] sourceArray = { 2, 5, 3, 8, 6, 5, 4, 15, 19, 32 };
// Displays the values of the Array.
Console.WriteLine( "Original values:" );
PrintValues(sourceArray);
// C# Extension Method: Array - Reverse
sourceArray.Reverse();
Console.WriteLine( "Values after calling Reverse method:" );
PrintValues(sourceArray);
}
public static void PrintValues(Array myArr)
{
int i = 0;
int cols = myArr.GetLength(myArr.Rank - 1);
foreach (object o in myArr)
{
if ( i < cols )
{
i++;
}
else
{
Console.WriteLine();
i = 1;
}
Console.Write( "\t{0}", o);
}
Console.WriteLine();
}
}