G
Guest
Hello,
I am trying to avoid using a DataTable to find particular data rows, because
I believe generic.list(of someobject) is faster. Unfortunately, two
seperately instantiated objects do not have the same hashcode so I am unable
to compare them within a Contains() call [even though they contain the same
data]. I know this is what primary keys are for but I wanted to know if
there is a way to use Contains() on a list object, such as:
Public Class SentenceContent
Public Sentence As String
Public Score As Integer
Public Sub New(ByVal Sentence As String, ByVal Score As Integer)
Me.Sentence = Sentence
Me.Score = Score
End Sub
End Class
Public Sentences As New Generic.List(Of SentenceContent)
Sentences.Add(New SentenceContent("testing", 1))
Sentences.Add(New SentenceContent("testing 1", 2))
Sentences.Add(New SentenceContent("testing 2", 3))
Sentences.Add(New SentenceContent("testing 3", 4))
Sentences.Add(New SentenceContent("testing 4", 5))
Sentences.Add(New SentenceContent("testing 5", 6))
Sentences.Add(New SentenceContent("testing 6", 7))
If Sentences.Contains(New SentenceContent("testing 5", 6)) Then
test.Text = "Contains" & "<br/>"
Else
test.Text = "NOT Contains" & "<br/>"
End If
I'm sure this is old news to you but I would very much appreciate your input
here.
Thanks!
mpaine
I am trying to avoid using a DataTable to find particular data rows, because
I believe generic.list(of someobject) is faster. Unfortunately, two
seperately instantiated objects do not have the same hashcode so I am unable
to compare them within a Contains() call [even though they contain the same
data]. I know this is what primary keys are for but I wanted to know if
there is a way to use Contains() on a list object, such as:
Public Class SentenceContent
Public Sentence As String
Public Score As Integer
Public Sub New(ByVal Sentence As String, ByVal Score As Integer)
Me.Sentence = Sentence
Me.Score = Score
End Sub
End Class
Public Sentences As New Generic.List(Of SentenceContent)
Sentences.Add(New SentenceContent("testing", 1))
Sentences.Add(New SentenceContent("testing 1", 2))
Sentences.Add(New SentenceContent("testing 2", 3))
Sentences.Add(New SentenceContent("testing 3", 4))
Sentences.Add(New SentenceContent("testing 4", 5))
Sentences.Add(New SentenceContent("testing 5", 6))
Sentences.Add(New SentenceContent("testing 6", 7))
If Sentences.Contains(New SentenceContent("testing 5", 6)) Then
test.Text = "Contains" & "<br/>"
Else
test.Text = "NOT Contains" & "<br/>"
End If
I'm sure this is old news to you but I would very much appreciate your input
here.
Thanks!
mpaine