C#相邻两数组元素同步长交换
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();
}
}
}
运行示例:
还没有评论,来说两句吧...