首页 > 代码库 > 数组反转显示

数组反转显示

class Program    {        static void Main(string[] args)        {            #region 数组内容反转            string[] names = { "马云", "李彦宏", "马化腾", "乔布斯", "比尔盖茨" };            ReverseArray(names);            for (int i = 0; i < names.Length; i++)            {                Console.WriteLine(names[i]);            }            Console.ReadKey();            #endregion        }        /// <summary>        /// 数组内容反转的方法        /// </summary>        /// <param name="names"></param>        private static void ReverseArray(string[] names)        {            for (int i = 0; i < names.Length / 2; i++)            {                string tmp = names[i];                names[i] = names[names.Length - 1 - i];                names[names.Length - 1 - i] = tmp;            }        }    }

显示结果:


 

数组反转显示