How can I “search” through a strongly typed list for a string?
I am attempting .Contains(TheString), however it errors stating Unable to cast object of type ‘System.String’ to type ‘o7thCrawler.Typing.ImportantTyping’
Here is the code:
Public Class LinkTyping
Public Property Url As String
Public Property Title As String
Public Property Content As String
End Class
If Not (_InternalUrls.Contains(_Url & _Link)) Then
_InternalUrls.Add(New Typing.LinkTyping() With {
.Url = _Url & _Link,
.Content = Item.Value,
.Title = If(Item.Attribute("title") IsNot Nothing,
Item.Attribute("title").Value,
Nothing)
})
End If
You’re trying to shoe-horn 2 types into the same list…
What type is
InternalUrls?This:
Implies it’s an
IList(Of String)but this:
Then tries to add a new instance of your LinkTyping class to it…
How about something like…
Make
InternalURLsbe aList(Of LinkTyping)Then
NB: The solution above assumes the URLs are going to be the same case for the purposes of matching (as does your example, assuming no overloaded comparison operator) – you may want to use a case-insensitive compare…