37 lines
630 B
Plaintext
37 lines
630 B
Plaintext
If you're using a ``++struct++``, 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
|
|
|
|
----
|
|
struct MyStruct // Noncompliant
|
|
{
|
|
private int i;
|
|
public int I
|
|
{
|
|
//...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
struct MyStruct : IEquatable<MyStruct>
|
|
{
|
|
private int i;
|
|
public int I
|
|
{
|
|
//...
|
|
}
|
|
|
|
public bool Equals(MyStruct other)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
----
|
|
|
|
|