I converted some c# code to vb.net and the converter.telerik.com turned this:
i--;
into this:
System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1)
Whats up with all the fancy-ness?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Michał Piaskowski’s comment triggered the following explanation:
The semantics of
i--in C# are to return the current value ofi(i.e., the value before the decrement occurs) and then decrementiby one.So, we need to convert that to VB. We can not use
i -= 1because this does not return the current value ofibefore the decrement. So, we need an operation that will decrementibut return the value ofibefore the decrement, something like:But this suggests using the following to avoid having to write a method to perform the above:
But VB.NET won’t let you use
i -= 1ori = i - 1in place ofsomeValueThatIsEqualToiMinusOne. However,System.Threading.Interlocked.Decrement(i)is legit and equal to the value ofi - 1. Once you do that, because parameters are evaluated left to right,someValueThatIsEqualtoiBeforeTheDecrementshould bei + 1(at that point the decrement has been performed toi + 1is the pre-decrement value.Note that the above method
DoPostDecrementand theSystem.Math.Max, System.Threading.Interlocked.Decrementconstruct could have different semantics in a multithreaded context.