Why is this an issue?
When a collection is empty, iterating it has no effect. Doing so anyway is likely a bug; either population was accidentally omitted, or the
iteration needs to be revised.
How to fix it
Code examples
Noncompliant code example
Public Sub Method()
Dim Values As New List(Of String)
Values.Remove("bar") ' Noncompliant
If Values.Contains("foo") Then ' Noncompliant
End If
For Each Value As String In Values ' Noncompliant
Next
End Sub
Compliant solution
Public Sub Method()
Dim Values As List(Of String) = LoadValues()
Values.Remove("bar")
If Values.Contains("foo") Then
End If
For Each Value As String In Values
Next
End Sub