Andy Andy - 4 months ago 7 Question

How can iterate in Dictionary in

I create a dictionary

Dim ImageCollection As New Dictionary(Of ConvensionImages, Integer)

and I fill that

For Each dr As DataRow In dt.Rows
Dim obj As New ConvensionImages
obj.ImageID = dr("ID")
obj.Name = dr("Name")
obj.Description = dr("Description")
obj.CategoryID = dr("CategoryID")
obj.CategoryName = dr("CategoryName")
obj.CategoryDescription = dr("CatDescription")
obj.EventID = dr("EventID")
obj.Image = dr("img")
obj.DownloadImage = dr("DownLoadImg")
ImageCollection.Add(obj, key)
key = key + 1

now I want to search ImageID and key how can I do this


Make Integer as key for your Dictionary:

Dim ImageCollection As New Dictionary(Of Integer, ConvensionImages)

Change ImageCollection.Add(obj, key) to ImageCollection.Add(key, obj)

And use this loop:

For Each kvp As KeyValuePair(Of Integer, ConvensionImages) In ImageCollection
     Dim v1 As Integer = kvp.Key  
     Dim v2 As ConvensionImages = kvp.Value  
     'Do whatever you want with v2:
     'If v2.ImageID = .... Then