I see this question.
How can I get the last element in a SortedDictionary in .Net 3.5.
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 use LINQ:
You can also get the last key:
You can even get the last key-value pair:
This will give you a
KeyValuePair<TKey, TValue>withKeyandValueproperties.Note that this will throw an exception if the dictionary is empty; if you don’t want that, call
LastOrDefault.