天涯之外

导航

泛型排序

 private class clsUser
        {
            public string username;
            public int userid;
            public clsUser(int uId,string uNm)
            {
                username = uNm;
                userid = uId;
            }
        }
        private List<clsUser> listUser=new List<clsUser>();

        private static int myCompare(clsUser user1,clsUser user2)
        {
            //比较规则,根据需要写
            if(user1==null || user2== null)
                return 0;
            if (user1.userid > user2.userid)
                return 1;
            if (user1.userid == user2.userid)
                return 0;
            if (user1.userid < user2.userid)
                return -1;
            return 0;
        }
        private void button1_Click(object sender, EventArgs e)
        {
             //这里调用
            listUser.Sort(myCompare);
        }

posted on 2009-02-17 11:55  天涯之外  阅读(161)  评论(0编辑  收藏  举报