30 lines
475 B
Plaintext
30 lines
475 B
Plaintext
![]() |
include::../description.adoc[]
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
public void DoSomething(string[] strings)
|
||
|
{
|
||
|
for (int i = 0; i < strings.Length; i--) // Noncompliant
|
||
|
{
|
||
|
string s = strings[i]; // IndexOutOfRangeException when i reaches -1
|
||
|
// do stuff
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
public void DoSomething(string[] strings)
|
||
|
{
|
||
|
for (int i = 0; i < strings.Length; i++)
|
||
|
{
|
||
|
string s = strings[i];
|
||
|
// do stuff
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
include::../see.adoc[]
|