Foreach Variable in C# generated code
In C# a foreach variable can't be assignable, so to avoid a compilation error, the line must be commented. In VB.Net the iteration variable can be assigned so, this restriction is not applied.
Check the logic of the original VB6 function. In some cases the nothing assignation to the iteration variable is a way to stop the cycle. If this is the case use the break statement instead.For the given example, just remove the commented line and the EWI.
Public Function TestCommentedLines(ByVal P() As String) As Integer
Dim Count As Integer
For Each S In P
If Not S IsNothing Then
Count = Count + 1
S = Nothing
TestCommentedLines = Count
public int TestCommentedLines( string P)
int Count = 0;
foreach (string S in P)
if (S != null)
//UPGRADE_NOTE: (2041) The following line was commented.
//S = null;