sorting - how to sort and display an arraylist based on points in c# -
i have array list named memberdata stores memberid, membername, memberpoint , other member data. want sort members based on memberpoint field.
here code:
public void displayallmembers() { int index = 1; console.writeline("all members"); console.writeline("no\t member name\t\t member id\t member point"); memberdata.sort(); foreach (object data in memberdata) { tempmember = (member)data; console.writeline("{0}\t\t {1} {2}\t\t {3}\t\t {4}", index, tempmember.givenname, tempmember.surname, tempmember.memberid, tempmember.memberpoint); index++; } }
you have use linq functions sorting depending on sorting directions this: sort in ascending order:
memberdata = memberdata.orderby(m=>m.memberpoint);
to sort in descending order :
memberdata = memberdata.orderbydescending(m=>m.memberpoint);
Comments
Post a Comment