我有一個自定義對象(DataPointCollection
),它具有兩個整型屬性和一個Guid屬性。我希望該對象生成一個HashCode,以便在這些屬性中沒有兩個具有相同值的對象被添加到HashSet中。我知道我需要重寫GetHashCode()
方法,但我該如何生成哈希代碼來完成此操作?生成對象的哈希代碼
下面是我想要如何使用它。
Dim dataPointCollections As New HashSet(Of DataPointCollection)()
For Each row As DataRow In myDataSet.Tables(0).Rows
Dim dataPointCollection As New DataPointCollection()
dataPointCollection.ProjectID = row("ProjectID") 'Integer'
dataPointCollection.RoleID = row("RoleID") 'Integer'
dataPointCollection.ResourceGUID = row("ResourceGUID") 'Guid'
If Not dataPointCollections.Contains(dataPointCollection) Then
dataPointCollections.Add(dataPointCollection)
End If
Next
我打開其他的想法,但我認爲這可能是比做對的對象集合的LINQ查詢更快的(有可能是一個非常大的數字,這些對象)。