Skip to content

How to retrieve top 10 elements in a Dictionary

George George

Asked Jul 21, 2008, 7:10 PM EDT2 answers
Share
LinkedInX

Hello everyone,


Suppose I have a Dictionary object instance, Dictionary<string, int>, the int is always positive. I want to get top 10 elements from the Dictionary with the maximum 10 int values, any efficient way to do this?


thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    use the System.Collection.Generic.specialized.SortedDictionary<string, int> oDictioanry  I think that could do the job you can moreover  use the  constructor  that  has  an  IComparer  to  compare  objects two  to  two
    0
  • 0

    Thanks Bechir,

     

    I think SortedDictionary sort by keys, not values. But I want to sort by values. Any comments or ideas?

     

    regards,

    George

    0