Array sort IComparer Compare 排序介绍|例子
public partial class Six : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string data = "",keys="123,456,666666,1,12";
string[] tempKeys = keys.Split(',');
Array.Sort(tempKeys, new myCompar());
foreach (string temp in tempKeys)
{
data += temp+"<br>";
//data = data.Replace(temp, string.Format("<font color='red'>{0}</font>", temp));
}
Response.Write(data);
}
}
public class myCompar : IComparer
{
int IComparer.Compare(Object x, Object y)///a.想知道x,y的具体含义
{
string tempX = x.ToString();
string tempY = y.ToString();
return tempX.Length - tempY.Length;
//如果x大于y返回正值 则是正序 反之则为倒序
}
}