include::../why-dotnet.adoc[]

== How to fix it

=== Code examples

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
public void Method()
{
    var values = new List<string>();
    values.Remove("bar");              // Noncompliant
    if (values.Contains("foo")) { }    // Noncompliant
    foreach (var str in values) { }    // Noncompliant
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
public void Method()
{
    var values = LoadValues();
    values.Remove("bar");
    if (values.Contains("foo")) { }
    foreach (var str in values) { }
}
----

include::../rspecator.adoc[]