How to use "For Each" with a dictionary

I've just started playing with dictionaries.  I have been able to iterate through a list using the "For Each" construct, but I have not been able to do it with a library.  Any suggestions would be appreciated.

For Each x As myObj In listContact
   '...code to process each x
Next

Dim dictContact As New Dictionary(Of Int32, MyObj)
   '...Add lots of Keys and MyObjs to dictContact, then
For Each x As MyObj in dictContact
   '...code to process each x
Next

This attempt at using the "For Each" for the dictionary won't compile.  Thanks.




Answer this question

How to use "For Each" with a dictionary

  • JoePD

    cgraus,

    Thanks, that solved my delima. I saw the Keys and Values methods, but hadn't put them together as a soluton to my problem.



  • Harshal Kherde

    For Each x As myObj In listContact.Keys

    For Each x As myObj In listContact.Values

    It might be .Items, not .Values, but it's certainly .Keys.



  • How to use "For Each" with a dictionary