What is the best for sorting a data table in c#, both from a performance and a code-readability point-of-view:
personsDT.OrderBy(person => person.PersonName);
or:
personsDT.DefaultView.Sort = 'PersonName ASC';
The personsDT is build from a SharePoint list, so it is impossible to use SQL (I am aware that an ORDER BY claude in a SQL SELECT statement would be the best way). Considering the performance, I am worried that the OrderBy<> clause might be slower than the Sort in the data view. Are you aware of such performance implications?
I’ll prefer the first option.
1) For code the readability point-of-view i think that Lambda is clearer than the second one.
2) In the first case you are using a strongly type way to sort your entity which is good.
3) On the second case you are passing the field and the order in a string mmmm dont like it.
Go Lambdas!!!
Regards!