rspec/rules/S3353/csharp/rule.adoc
2022-02-04 16:28:24 +00:00

47 lines
857 B
Plaintext

Marking a variable that is unchanged after initialization ``++const++`` is an indication to future maintainers that "no this isn't updated, and it's not supposed to be". ``++const++`` should be used in these situations in the interests of code clarity.
== Noncompliant Code Example
[source,csharp]
----
public bool Seek(int[] input)
{
int target = 32; // Noncompliant
foreach (int i in input)
{
if (i == target)
{
return true;
}
}
return false;
}
----
== Compliant Solution
[source,csharp]
----
public bool Seek(int[] input)
{
const int target = 32;
foreach (int i in input)
{
if (i == target)
{
return true;
}
}
return false;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]