And*_*ndy 28 vb.net dictionary
我创建了一本字典
Dim ImageCollection As New Dictionary(Of ConvensionImages, Integer)
Run Code Online (Sandbox Code Playgroud)
我填写
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
Run Code Online (Sandbox Code Playgroud)
现在我想搜索ImageID和密钥我该怎么做呢
And*_*eev 57
请Integer为您的字典键:
Dim ImageCollection As New Dictionary(Of Integer, ConvensionImages)
Run Code Online (Sandbox Code Playgroud)
更改ImageCollection.Add(obj, key)到ImageCollection.Add(key, obj)
并使用此循环:
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
Next
Run Code Online (Sandbox Code Playgroud)
Sys*_*gon 15
你也可以这样循环:
For Each iKey As Integer In ImageCollection.Keys
Dim value As ConvensionImages = ImageCollection(iKey)
'...
Next
Run Code Online (Sandbox Code Playgroud)
这是非常快速和简单的方法.