I have a List<MyClass> and I want to sort it by DateTime CreateDate attribute of MyClass.
Is that possible with LINQ ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can enumerate it in sorted order:
You can also use
ToList()to convert to a new list and reassign to the original variable:This isn’t quite the same as sorting the original list because if anyone still has a reference to the old list they won’t see the new ordering. If you actually want to sort the original list then you need to use the
List<T>.Sortmethod.