vb.net中键值列表或字典的通用结果
我需要在我的DNN安装中返回州(地区)名称及其缩写值的键值配对列表。在下面的函数中,我成功地向名为RegionList的推断变量获取了所需的结果,但是我无法将这些结果转换为键值配对列表或字典并返回结果。任何帮助都将不胜感激vb.net中键值列表或字典的通用结果,vb.net,dictionary,collections,key-value,Vb.net,Dictionary,Collections,Key Value,我需要在我的DNN安装中返回州(地区)名称及其缩写值的键值配对列表。在下面的函数中,我成功地向名为RegionList的推断变量获取了所需的结果,但是我无法将这些结果转换为键值配对列表或字典并返回结果。任何帮助都将不胜感激 Public Function GetRegionPerCountry(CountryCode As String) As List(Of KeyValuePair(Of String, String)) Dim lc As New DotNetNuke.Common
Public Function GetRegionPerCountry(CountryCode As String) As List(Of KeyValuePair(Of String, String))
Dim lc As New DotNetNuke.Common.Lists.ListController()
Dim countryID As Integer
Dim RegionList2 As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))
If Not CountryCode Is Nothing Then
Dim entryCollection As System.Collections.Generic.List(Of DotNetNuke.Common.Lists.ListEntryInfo)
entryCollection = lc.GetListEntryInfoItems("Country")
countryID = entryCollection.Where(Function(x) x.Value = CountryCode).Select(Function(x) x.EntryID).FirstOrDefault()
entryCollection = lc.GetListEntryInfoItems("Region")
Dim RegionList = entryCollection.Where(Function(x) x.ParentID = countryID).Select(Function(x) New With {.Key = x.Text.ToString(), .Value = x.Value.ToString()}).ToList()
RegionList2 = RegionList
End If
Return RegionList2
End Function
试试returnregionList2.Key.Tostring()哎呀,你想要的是一个列表,而不是字符串本身。我会做一个断点,并确保regionList是您期望的变量类型。