这是我的代码..
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”。