Reputation: 702
I'm making a program in c# and I got a list with objects which I want to sort with c#. I can't get it working nor do I understand how it should be implemented.
I did some research for which algorithm I should use and came up with merge sort because it's always n(log n) and doesn't rely on a lucky chance with the pivot like quick sort to achieve it.
Anyways so far why I chose that and want it. :)
it's a list with weight each weight contains a date and a bodyweight. I want to get it sorted on the date and make the method return the sorted list.
Could someone help me to achieve this. You would help me out a lot :)
Thanks in advance
Upvotes: 1
Views: 678
Reputation: 2546
You can use linq to sort collections, for example:
public IEnumerable<Weight> GetSortedWeights()
{
var weights = new List<Weight>() { new Weight { Date = DateTime.Now, BodyWeight = 80 }, ... };
return weights.OrderBy(x => x.Date);
}
Upvotes: 2