I have this Dictionary
Dictionary<Guid, DateTime> myDic = new Dictionary<Guid, DateTime>();
What is the best approach to sort it DESC by DateTime? Is it LINQ?
How it could be done in code?
Thank you!
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 have the wrong data structure to achieve what you want. The purpose of a dictionary is to provide fast access by key. A SortedDictionary exists that sorts its own keys, but there is no dictionary that sorts its values because that doesn’t make sense.
Assuming all you need is the DateTimes contained in myDic sorted descending, you could do:
That will allow you to enumerate the values in descending order, but will not sort the dictionary.