This question is locked. New answers and comments are not allowed.
Hi
The following code in C#
gets converted to VB in such a strange way:
Try to convert the converted code back to C#:
Some questions:
(1) Why must the for loop be converted to while? VB also has for loop! The logic is still there but the question is, why must the converter use while?
(2) The increment for i, why can't it be simpler like i = i+1? Why must it use System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1), which looks mysterious? And this mysterious code remains the same when the converted code is converted back to VB!
(3) The converter is smart enough to change the array index from [ ] in C# to ( ) in VB, but is unable to change it back, which would of course cause syntax error when compiling the converted code.
Can any of this be improved?
The following code in C#
protected string Testing(string st) |
{ |
string st2 = ""; |
for (int i = st.Length - 1; i >= 0; i--) |
st2 = st2 + st[i]; |
return st2; |
} |
gets converted to VB in such a strange way:
Protected Function Testing(ByVal st As String) As String |
Dim st2 As String = "" |
Dim i As Integer = st.Length - 1 |
While i >= 0 |
st2 = st2 + st(i) |
System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1) |
End While |
Return st2 |
End Function |
Try to convert the converted code back to C#:
protected string Testing(string st) |
{ |
string st2 = ""; |
int i = st.Length - 1; |
while (i >= 0) { |
st2 = st2 + st(i); |
System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1); |
} |
return st2; |
} |
Some questions:
(1) Why must the for loop be converted to while? VB also has for loop! The logic is still there but the question is, why must the converter use while?
(2) The increment for i, why can't it be simpler like i = i+1? Why must it use System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1), which looks mysterious? And this mysterious code remains the same when the converted code is converted back to VB!
(3) The converter is smart enough to change the array index from [ ] in C# to ( ) in VB, but is unable to change it back, which would of course cause syntax error when compiling the converted code.
Can any of this be improved?