だから私はこの(VB、ごめんなさい)オブジェクトを持っています:
Class Foo
Private ReadOnly foo as Integer
Public Overridable ReadOnly Property Foo() as Integer
Get
Return foo
End Get
End Property
Public Overridable Overloads Function Equals(ByVal other as Foo) as Boolean
Return Me.foo.Equals(other.foo)
End Function
Public Overloads Overrides Function Equals(ByVal obj as Object) as Boolean
... some boilerplate ...
Return Equals(DirectCast(obj, Foo))
End Function
End Class
大きな謎は、データベースからオブジェクトをロードすると、 inの値が正しいにもかかわらず、 in が常にゼロになることですEquals()
。other.foo
Foo()
これはどうやってできるの?
Equals メソッドの別のバージョンは次のとおりです。
Private Overloads Function Equals(ByVal other as Foo) as Boolean Implements IEquatable(Of Foo).Equals
Return Me.foo.Equals(other.foo)
End Function
そして、このバージョンでは、との両方 がゼロです。Me.foo
other.foo