string[] s = new string[3] { "", "", "好人" };
              for (int i = 0; i < s.Length/2; i++)  //若字符串个数为奇数,则交换了(s.length-1)/2,若是偶数,则交换了s.length/2.
            {
                string temp = s[i];
                s[i] = s[s.Length - 1-i];    //定义一个新的变量实现交换。
                s[s.Length - 1-i] = temp;
                for (int j = 0; j < s.Length; j++)
                {
                    Console.Write(s[j]);              //输出交换完的数组。。
                }
            }
         
            Console.ReadKey();

例2:

            string[] arry = new string[] { "张三", "李四", "赵五", "孙六", "周⑦", "王八" };
            int count = arry.Length;
            for (int i = 0; i < count / 2; i++)
            {
                string temp = arry[i];
                arry[i] = arry[count - 1 - i];
                arry[count - 1 - i] = temp;
            }
            for (int j = 0; j < count; j++)
            {
                Console.Write(arry[j] + "\t");
            }
            Console.ReadLine();

 

相关文章:

  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2021-11-15
  • 2021-06-10
猜你喜欢
  • 2021-05-22
  • 2021-10-28
  • 2021-10-30
  • 2022-01-24
  • 2021-12-28
  • 2021-10-04
相关资源
相似解决方案