45 lines
862 B
Plaintext
45 lines
862 B
Plaintext
== Why is this an issue?
|
|
|
|
Using ``++Object.ReferenceEquals++`` to compare the references of two value types simply won't return the expected results most of the time because such types are passed by value, not by reference.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
public class MyClass
|
|
{
|
|
private MyStruct myStruct;
|
|
|
|
public void DoSomething(MyStruct s1) {
|
|
int a = 1;
|
|
int b = 1;
|
|
|
|
if (Object.ReferenceEquals(myStruct, s1)) // Noncompliant; this can never be true
|
|
{
|
|
// ...
|
|
}
|
|
else if (Object.ReferenceEquals(a,b)) // Noncompliant
|
|
{
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|