这段代码可以把C#的数组倒置过来,主要用到了Array.Reverse方法
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(); } }
输出结果如下:
Array elements: beta alpha gamma gamma alpha beta