我有一位理论家,其钥匙是Excel平地物体(无,不流通),定义如下(电池组是一种含有各种细胞特性的物体):
Dim dic As New Dictionary(Of Excel.Range, CellProp)(New RangeComparer())
由于钥匙是物体,我需要超负荷行使平等/平等职能。 我目前的执行情况如下:
Class RangeComparer
Implements IEqualityComparer(Of Excel.Range)
Public Overloads Function Equals(ByVal x As Excel.Range, ByVal y As Excel.Range) As Boolean Implements IEqualityComparer(Of Excel.Range).Equals
If x.Address(External:=True) = y.Address(External:=True) Then
Return True
Else
Return False
End If
End Function
Public Overloads Function GetHashCode(ByVal obj As Excel.Range) As Integer Implements IEqualityComparer(Of Excel.Range).GetHashCode
Return obj.Count.GetHashCode
End Function
End Class
However, this can be pretty slow to execute when adding many cells (i.e. hundreds) to the Dictionary at once. Most importantly, is there a faster way to do this? Secondarily, why does getting the hash code for the Range s Count property seem to work (albeit slowly)?