小排序

View Code
            string[] arry = new string[5];
arry[0] = "广东|30";
arry[1] = "湖南|20";
arry[2] = "广西|60";
arry[3] = "北京|70";
arry[4] = "上海|30";
for (int i = 0; i < arry.Length-1; i++)
{
for (int j = i; j < arry.Length-1; j++)
{
int num1=Convert.ToInt32(arry[j].Split('|')[1]);
int num2 = Convert.ToInt32(arry[j+1].Split('|')[1]);
if (num1>num2)
{
string temp = arry[j];
arry[j] = arry[j+1];
arry[j + 1] = temp;
}
}
}

foreach (string item in arry)
{
Response.Write(item + "<br />");
}
原文地址:https://www.cnblogs.com/walleyekneel/p/2229275.html