3

我想检索 Dictionary 数组中有多少项:

在此处输入图像描述

但是执行以下操作似乎不会产生应有的4

Dim showNumber As Integer = tmpShows.Length

我拥有的字典的代码是这样的:

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://example.org" & 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)
4

3 回答 3

7

使用Count而不是length

例子:

Dim showNumber As Integer = tmpShows.Count
于 2012-11-11T05:15:50.223 回答
0

我这样做只是为了让我的计数......

 Dim intXShows As Integer = 0

 For Each item In tmpShows
    intXShows += 1
 Next
于 2012-11-12T01:47:41.083 回答
0

尝试像这样更改您的声明:

Dim all as New Dictionary(Of String, Object)()

代替:

Dim all = New Dictionary(Of String, Object)()

然后调用Count,Length等。

还可以尝试使用ForEach循环来获取all变量的计数。

于 2012-11-14T16:39:42.523 回答