int[] arr={1,2,3,4,5,6,7,8,9};
for(int i=0;i{
for(int j=i+1;j{
int tmp=arr[j];
arr[j]=arr[i];
arr[i]=tmp;
break; //跳出j循环,继续i循环。
}
}
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Array.Sort(arr, new MyComparer());
}
class MyComparer : IComparer
{
public int Compare(int x, int y)
{
Int32 mx = x % 2;
Int32 my = y % 2;
return (mx == my) ? x.CompareTo(y) : my - mx;
}
}
}