How to retrive an item from an dictionary object using an Index? eg i have a dicitiory object of 10 items and i have to get the 5th keypairvalue from the dictionary?
Share
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.
Dictionaries are unordered. If you mean “the 5th item added to the dictionary” – they don’t provide this functionality.
One thing to be careful of is that in many cases
Dictionary<TKey, TValue>appears to be ordered – if you just add a bunch of entries and then iterate, then under the current implementation I believe you will at least usually get back the pairs in the same order. However, it’s not guaranteed, it’s not meant to happen particularly – it’s just a quirk of the implementation. If you delete entries and then add more, then the whole thing goes pear-shaped.Fundamentally, if you want ordering as well as key lookups, you need to store a list as well as a dictionary.