how looping over a dictionary by loop for

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • skneife@gmail.com

    how looping over a dictionary by loop for

    I need to access to a dictionary by its index like a string array.
    Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
    for (int item = 0; item < tdmDx1.Count; item++) {

    .... how access item by its index ???

    }

    Sam
  • Paul E Collins

    #2
    Re: how looping over a dictionary by loop for

    <skneife@gmail. comwrote:
    I need to access to a dictionary by its index like a string array.
    Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
    for (int item = 0; item < tdmDx1.Count; item++) {
    .... how access item by its index ???
    foreach (KeyValuePair<s tring, stringkv in tdmDx1)

    Eq.


    Comment

    • Brian Gideon

      #3
      Re: how looping over a dictionary by loop for

      On Apr 27, 5:42 pm, skne...@gmail.c om wrote:
      I need to access to a dictionary by its index like a string array.
      Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
      for (int item = 0; item < tdmDx1.Count; item++) {
      >
         .... how access item by its index ???
      >
      }
      >
      Sam
      You can't because the Dictionary class is implemented with a hashtable
      so the index doesn't make much sense. Let me ask you this...what
      would you want the index value of 0 to mean? That might help us
      determine what kind of collection best fits your needs.

      Comment

      • =?Utf-8?B?VGFudHIgTWFudHI=?=

        #4
        RE: how looping over a dictionary by loop for

        Sam, Not sure why you need to loop thru a dictionary using index, but have
        you had a look at wintellect's power collections
        (http://www.wintellect.com/PowerCollections.aspx). The OrderedDictiona ry
        might be what you are looking for.

        Cheers!

        "skneife@gmail. com" wrote:
        I need to access to a dictionary by its index like a string array.
        Dictionary<stri ng, stringtdmDx1 = new Dictionary<stri ng, string>();
        for (int item = 0; item < tdmDx1.Count; item++) {
        >
        .... how access item by its index ???
        >
        }
        >
        Sam
        >

        Comment

        Working...