using System;
using System.Collections;
using System.Collections.Generic;

namespace OOP
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] chIndex = new int[] { 1, 2, 3, 4, 5, 6 };
            for (int i = 0; i <= 4; i += 2)
            {
                int temp = chIndex[i];
                chIndex[i] = chIndex[i + 1];
                chIndex[i + 1] = temp;
            }
            for (int i = 0; i < chIndex.Length; i++)
            {
                Console.Write(chIndex[i] + "\t");
            }
            Console.ReadKey();
        }
    }
}

运行示例:
在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐