I'm converting my application from .Net 4.0 to .Net 4.5 Framework and there is a change in the List<>
definition.
My old code looked like this (.Net 4.0):
List<Customer> list = new List<Customer>();
list.Add(new Customer("Smith", "John", "Sydney", 45));
list.Add(new Customer("Mitchell", "Brad", "New York", 52));
list.Add(new Customer("Baker", "William", "Cape Town", 21));
list.OrderBy(x => x.Name);
Using .Net 4.5 (C#5) the List<T>.OrderBy()
method is gone and only List<T>.Sort()
is available, but it looks like there is no possibility to use a Lambda expression with this method.
Is there any option other than defining a IComparer
for every <T>
?
If there is really no option for a Lambda expression, I could life with a generic IComparer
, but how to choose the property to be compared?
Solved/Edit:
using Linq;
[...]
List<Customer> list = new List<Customer>();
list.Add(new Customer("Smith", "John", "Sydney", 45));
list.Add(new Customer("Mitchell", "Brad", "New York", 52));
list.Add(new Customer("Baker", "William", "Cape Town", 21));
list.OrderBy(x => x.Name); //list stays unordered
list = list.OrderBy(x => x.Name).ToList(); // list content is now ordered