rspec/rules/S2995/csharp/rule.adoc

25 lines
565 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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
----
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
{
// ...
}
}
}
----