32 lines
765 B
Plaintext
32 lines
765 B
Plaintext
![]() |
If you're using a `Structure`, it is likely because you're interested in performance. But by failing to implement `IEquatable<T>` you're loosing performance when comparisons are made because without `IEquatable<T>`, boxing and reflection are used to make comparisons.
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
[source,vbnet]
|
||
|
----
|
||
|
Structure MyStruct ' Noncompliant
|
||
|
|
||
|
Public Property Value As Integer
|
||
|
|
||
|
End Structure
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
[source,vbnet]
|
||
|
----
|
||
|
Structure MyStruct
|
||
|
Implements IEquatable(Of MyStruct)
|
||
|
|
||
|
Public Property Value As Integer
|
||
|
|
||
|
Public Overloads Function Equals(other As MyStruct) As Boolean Implements IEquatable(Of MyStruct).Equals
|
||
|
' ...
|
||
|
End Function
|
||
|
|
||
|
End Structure
|
||
|
----
|
||
|
|
||
|
include::../see.adoc[]
|
||
|
include::../rspecator.adoc[]
|