Using C# in .Net 2.0
When someone joins my server, I want to add their name, and the DateTime that they joined to a list/dictionary, as well as their score, which gets updated frequently.
I then want to be able to sort that list/dictionary by the DateTime or score, based on a boolean value, so that I can return the top 50% of the list/dictionary. i.e. return the names of the top 50% longest time between join and now, or the top 50% scores.
I’ve attempted it using two separate dictionaries, then using a custom sort by value method, but it’s messy, and doesn’t seem to work.
Is there an elegant way of doing this?
You could create a class to represent each user:
Then if you have a list of users
you could sort it by score:
or by date joined:
If you can use C# 3 or later then this gets a lot nicer with Linq and Lambda expressions.
For example: