Hello (and best wishes),
I have seen an error where the converted code doesn't give the expected result.
Input code
Public Class VisualBasicClass
Public sub Test
dim LstTmp as new List (of Integer)
LstTmp.Add (5)
LstTmp.Add (6)
LstTmp.Add (7)
LstTmp.Add (8)
LstTmp.Add (9)
LstTmp.Add (10)
dim i_Total as integer
for each CurVal as integer in LstTmp
i_Total +=CurVal
Select case CurVal
Case 6
Exit For
End select
Next
Messagebox.show (i_Total.Tostring())
End Sub
End Class
Erroneous output
public void Test()
{
var LstTmp = new List<int>();
LstTmp.Add(5);
LstTmp.Add(6);
LstTmp.Add(7);
LstTmp.Add(8);
LstTmp.Add(9);
LstTmp.Add(10);
var i_Total = default(int);
foreach (int CurVal in LstTmp)
{
i_Total += CurVal;
switch (CurVal)
{
case 6:
{
break;
}
}
}
MessageBox.Show(i_Total.ToString());
}
Expected output
public void Test()
{
var LstTmp = new List<int>();
LstTmp.Add(5);
LstTmp.Add(6);
LstTmp.Add(7);
LstTmp.Add(8);
LstTmp.Add(9);
LstTmp.Add(10);
var i_Total = default(int);
foreach (int CurVal in LstTmp)
{
bool bo_ExitFor = false;
i_Total += CurVal;
switch (CurVal)
{
case 6:
{
bo_ExitFor = true;
break;
}
}
if (bo_ExitFor) break;
}
MessageBox.Show(i_Total.ToString());
}
Details
- Product in use: VS extension
- Version in use: e.g. 8.2.1
- It didn't work before
- It is also possible to do a function with a return Value of true to trigger the Break
It should at least give an error because the code doesn't work like before (VB ==> 11 and C#==>45).
It is also possible to convert to if (.....) but you lose some visibility.
Hello (and best wishes),
I have seen an error where the converted code doesn't give the expected result.
Input code
Erroneous output
Expected output
Details
It should at least give an error because the code doesn't work like before (VB ==> 11 and C#==>45).
It is also possible to convert to if (.....) but you lose some visibility.