泛型排序
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);
}
{
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);
}