数组反转显示

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;
            }
        }
    }

显示结果:


************Code虽易,Debug不易,且码且珍惜************


本博客仅用于学习记录之用,如有侵权,请Email:tianqy@live.com

原文地址:https://www.cnblogs.com/tianqy/p/3983379.html