1

这是我的代码..

Private Function GetElement(ByVal hec As ICollection, ByVal strAttName As String, ByVal strAttVal As String) As List(Of HtmlElement)
    Dim hecFilter As New List(Of HtmlElement)
    Dim str As String
    For Each El As HtmlElement In hec
        str = El.GetAttribute(strAttName)
        If (Not IsNothing(str) AndAlso str.Trim() = strAttVal) Then
            hecFilter.Add(El)
        End If
    Next
    Return hecFilter
End Function

它会回报我List(Of HtmlElement)

现在我想把它转换成HtmlElementCollection class.

试图做到这一点

Private Function GetElement(ByVal hec As HtmlElementCollection, ByVal strAttName As String, ByVal strAttVal As String) As HtmlElementCollection
    Dim hecFilter As New List(Of HtmlElement)
    Dim str As String
    For Each El As HtmlElement In hec
        str = El.GetAttribute(strAttName)
        If (Not IsNothing(str) AndAlso str.Trim() = strAttVal) Then
            hecFilter.Add(El)
        End If
    Next
    Return TryCast(hecFilter, HtmlElementCollection)
End Function

它显示一个错误:

“System.Collections.Generic.List(Of System.Windows.Forms.HtmlElement)”类型的值无法转换为“System.Windows.Forms.HtmlElementCollection”。

4

1 回答 1

0

HtmlElementCollection 没有的工具ICollection没有 ..Add()IEnumerable

我猜构造函数接受元素是internal. 因此威胁此集合为只读。

于 2013-04-14T06:49:01.287 回答