我有一个自定义对象(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查询更快的(有可能是一个非常大的数字,这些对象)。