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