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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -