-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VB -> C#: Error converting a For loop #602
Comments
Hi thanks for getting in touch. Can you tell me about what problem the erroneous output is causing you? Is it that it doesn't compile (e.g. Missing reference to Conversions), does the wrong thing, or you just don't like the look of it? I believe the loopTo variable more accurately reflects what VB does. I.e. If a method in the loop, or another thread changes the length of Old Words, I think your suggested output would behave differently to the VB. The Conversions method looks entirely redundant, and shouldn't be generated if there's type information. Were the variables or properties defined with types? |
The loopTo variable is non existent and never gets changed in the loop, thus rendering it useless. The OldWords array never changes, especially in the for loop.
|
Ah, now I'm reading on a proper-sized screen I see you've used a boolean as the limit on your for loop which is very unusual and will have surprising results (I think never entering the loop). Based on your expected output (converting it back to VB) your input should probably have been this: For i As Integer = 0 To OldWords.Length - 1
HTMLCode = HTMLCode.Replace(OldWords(i), NewWords(i))
Next For that input, it does then convert to C# correctly - actual converted output: for (int i = 0, loopTo = OldWords.Length - 1; i <= loopTo; i++)
HTMLCode = HTMLCode.Replace(OldWords[i], NewWords[i]); But even though I think it was a bug that lead here the bug report is still relevant. The VB you gave does compile (when the variables are defined), and is a feature people sometimes intentionally use in VB, so I'll try and improve the converter support around it at some point. Hope that makes sense. Let me know if I've misunderstood, thanks for reporting! |
I've handled the boolean To expression case. The fix will be in the next release. |
Yes, you understood correctly :) |
@FeaXR: Please retest. New version is already available |
Input code
Erroneous output
Expected output
Details
The text was updated successfully, but these errors were encountered: