C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

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返回正值 则是正序 反之则为倒序
 

        }
    }

posted on 2011-05-03 16:12  王德田  阅读(411)  评论(0编辑  收藏  举报