嘿,我在VB.net的这个Dictionary类中是新手。
我想重新检索Dictionary数组中有多少项:
但是这样做:
Dim showNumber As Integer = tmpShows.Length
似乎不应该产生 4 吗?
我所拥有的词典的代码是:
Dim all = New Dictionary(Of String, Object)()
Dim info = New Dictionary(Of String, Object)()
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(3).ChildNodes(2).InnerText
info!Shows = From tag In .SelectNodes(".//a[@class='thickbox']")
Select New With {.Show = tag.Attributes("title").Value, .Link = tag.Attributes("href").Value}
Dim tmpShows = all.Item(info!Station)
Dim showNumber As Integer = tmpShows.Length
为了获得 4 长度,我缺少什么?
更新
Dim all = New Dictionary(Of String, Object)()
For Each channel In doc.DocumentNode.SelectNodes(".//div[@class='channel_row']")
Dim info = New Dictionary(Of String, Object)()
skipFirstShow = False
With channel
info!Logo = .SelectSingleNode(".//img").Attributes("src").Value
info!Channel = .SelectSingleNode(".//span[@class='channel']").ChildNodes(3).ChildNodes(0).InnerText
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(3).ChildNodes(2).InnerText
Dim style As String = .SelectSingleNode(".//span[2]").Attributes("style").Value
If InStr(style.ToLower, "width: 0px;") <> 0 Then skipFirstShow = True
info!Shows = From tag In .SelectNodes(".//a[@class='thickbox']")
Select New With {.Show = tag.Attributes("title").Value, .Link = tag.Attributes("href").Value}
'Select New With {.Show = tag.Attributes("title").Value, .Link = tag.Attributes("href").Value}
End With
all.Add(info!Station, info.Item("Shows"))
theLogoURL(theCount) = "https://xxx.com" & Trim(info.Item("Logo"))
theChannelNum(theCount) = Trim(info.Item("Channel"))
theStationCallLetters(theCount) = Trim(info.Item("Station"))
Dim Shows As String = ""
Dim ShowsDetail As String = ""
Dim tmpShows = all.Item(info!Station)
答案 0 :(得分:6)
使用Count代替长度。
示例:
Dim showNumber As Integer = tmpShows.Count
答案 1 :(得分:0)
我这样做是为了得到我的统计......
Dim intXShows As Integer = 0
For Each item In tmpShows
intXShows += 1
Next
答案 2 :(得分:0)
您是否尝试过这样更改声明:
Dim all as New Dictionary(Of String, Object)()
而不是:
Dim all = New Dictionary(Of String, Object)()
然后拨打Count
,Length
等等。
还可以尝试使用ForEach
循环来计算all
变量。