我看到了这里提出的问题:我是否正确实现了 Equals()/GetHashCode()?但是我的 c# 没有那么强大,而且我对 IEquatable 不够熟悉,如果可能的话,我想在 VB.NET 中看到它。
我的示例代码(当我到达那里时,该类最终将使用 INotifyPropertyChanged):
Public Class Car
Implements ICloneable
Implements IEquatable(Of Car)
Public Property Make() As String
Get
Return m_Make
End Get
Set(ByVal value As String)
m_Make = value
End Set
End Property
Private m_Make As String
Public Property Model() As String
Get
Return m_Model
End Get
Set(ByVal value As String)
m_Model = value
End Set
End Property
Private m_Model As String
Public Function Clone() As Object Implements System.ICloneable.Clone
Return New Car() With { _
.Make = Me.Make, _
.Model = Me.Model _
}
End Function
Public Overloads Function Equals(ByVal other As Car) As Boolean Implements System.IEquatable(Of Car).Equals
Return other.Make = Me.Make AndAlso other.Model = Me.Model
End Function
End Class
谢谢,