Results 1 to 3 of 3

Thread: Accessing Dictionary by Index

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved Accessing Dictionary by Index

    I need to access the Dictionary by it's index (not the key). How do I go about doing this?

    Thanks.
    Last edited by nebulom; Feb 28th, 2007 at 10:43 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Accessing Dictionary by Index

    You don't. A Dictionary has no concept of order, only of correspondence between key and value. You can loop through all the values using the Values property. You can also loop through all the Keys using the Keys property, then getting the value for each key if desired. If order is important then you can use a SortedDictionary or SortedList.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Accessing Dictionary by Index

    Hmm Ok. I just feed it to List<Something> list = new List<Something>(myDictionary.Values) and then I'll get the list[0], list[3]...

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width