Linq Dictionary question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eps

    Linq Dictionary question

    Hi there,

    Say I have a dictionary of the type...

    Dictionary<Colo r, int>

    how would I get the 5 key value pairs with the greatest value (the value
    being the integer).

    It should be simple but I have been struggling to do it in Linq, any
    examples would be much appreciated.

    Regards.

    --
    Eps
  • Pavel Minaev

    #2
    Re: Linq Dictionary question

    On Aug 6, 1:04 pm, Eps <msnewsgro...@e pscylonb.comwro te:
    Hi there,
    >
    Say I have a dictionary of the type...
    >
    Dictionary<Colo r, int>
    >
    how would I get the 5 key value pairs with the greatest value (the value
    being the integer).
    Dictionary<Colo r, intdict;
    ...
    IEnumerable<Key ValuePair<Color , Int>result =
    dict.OrderByDes cending(pair =pair.Value).Ta ke(5);

    Comment

    • Eps

      #3
      Re: Linq Dictionary question

      Pavel Minaev wrote:
      On Aug 6, 1:04 pm, Eps <msnewsgro...@e pscylonb.comwro te:
      >Hi there,
      >>
      >Say I have a dictionary of the type...
      >>
      >Dictionary<Col or, int>
      >>
      >how would I get the 5 key value pairs with the greatest value (the value
      >being the integer).
      >
      Dictionary<Colo r, intdict;
      ...
      IEnumerable<Key ValuePair<Color , Int>result =
      dict.OrderByDes cending(pair =pair.Value).Ta ke(5);
      >
      ok I new it would be simple :)

      what happens if there are less then five kvp's in the dictionary, is
      there an exception thrown ?, I guess I should check the number of items
      anyway right ?.

      thanks.

      --
      Eps

      Comment

      • =?Utf-8?B?UGFua2Fq?=

        #4
        RE: Linq Dictionary question

        Please go to http://www.a2zdotnet.com/Default.aspx
        for step by step tutorials for beginers in LINQ sections.

        --
        regards,
        Pankaj
        最近2019好看的中文字幕_在线天堂中文WWW官网_制服丝袜日韩中文字幕在线_色综合久久中文综合网_中文字幕无码无码专区_亚洲中文字幕无码永久在线_中文字幕你懂的



        "Eps" wrote:
        Hi there,
        >
        Say I have a dictionary of the type...
        >
        Dictionary<Colo r, int>
        >
        how would I get the 5 key value pairs with the greatest value (the value
        being the integer).
        >
        It should be simple but I have been struggling to do it in Linq, any
        examples would be much appreciated.
        >
        Regards.
        >
        --
        Eps
        >

        Comment

        • Peter Duniho

          #5
          Re: Linq Dictionary question

          On Mon, 11 Aug 2008 08:56:12 -0700, Pankaj
          <Pankaj@discuss ions.microsoft. comwrote:
          Please go to [Pankaj's spam web site]
          for step by step tutorials for beginers in LINQ sections.
          Please stop spamming. These kinds of posts are not welcome.

          Comment

          Working...