怎么可以在vb.net中的Dictionary中迭代?

前端之家收集整理的这篇文章主要介绍了怎么可以在vb.net中的Dictionary中迭代?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建一个字典
Dim ImageCollection As New Dictionary(Of ConvensionImages,Integer)

我补充了

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

现在我想搜索ImageID和密钥我该怎么做

Make Integer作为您的词典的关键:
Dim ImageCollection As New Dictionary(Of Integer,ConvensionImages)

将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
原文链接:https://www.f2er.com/vb/255988.html

猜你在找的VB相关文章