Reverse order of array elements
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Code Snippets |
| See also |
| edit |
This C# code snippet puts the elements of an array in reverse order.
using System; public class ReverseArray { public static void Main() { string[] strings = {"beta", "alpha", "gamma"}; Console.WriteLine ("Array elements: "); DisplayArray (strings); Array.Reverse (strings); // Reverse element order DisplayArray (strings); } public static void DisplayArray (Array array) { foreach (object o in array) { Console.Write ("{0} ", o); } Console.WriteLine(); } }
| Reverse array example (program output) |
| Array elements: beta alpha gamma gamma alpha beta |