Forum C# Sorting Player Object

Sorting Player Object

Postby wbsaputra » December 26th, 2010, 4:44 pm

maybe this is a dumb question, just want to know how can i sort Player based on their properties?
example there are 5 players joining room, each player has different score. I want to set their turn in game from the lowest score to highest. score is loaded from database object when player joining room.
thanks for any help
wbsaputra
Paid Member
 
Posts: 150
Joined: June 29th, 2010, 4:38 pm

Re: Sorting Player Object

Postby TobiasW » December 26th, 2010, 7:22 pm

Game<P>.Players is an IEnumerable and as such you can only read it, so first you'll have to create your own sorted List<Player>.

Then you could use something like this for sorting:
Code: Select all
SortedPlayers.Sort(delegate(Player p1, Player p2) { return p1.score < p2.score; });
User avatar
TobiasW
 
Posts: 59
Joined: August 29th, 2010, 12:31 am


Return to C#



cron