Per the discussion here, one of the answers seems to imply that by using a code converter from C# to VB.NET, that the operator++ applied to an int should be replaced by System.Math.Max(System.Threading.Interlocked.Increment(current),current - 1))
, I wondered if this is actually correct?
If so, why is it correct? I didn't think that operator++ would be implemented as an Interlocked.Increment operation? I didn't even think it was threadsafe. I'm failing to see who these two are the same, and then why the answer to the question linked to, even works?
I tried it and it produces the correct result. AFAIK, .NET has no such thing as undefined behaviour, as C++ does.
Can anybody clarify?
You can do x += 1
in VB.Net. Not as elegant as x++, but better than x = x + 1.
Interlocked.Increment is for making your add operation thread-safe. You may not need it at all.
EDIT: Also, if it wasn't clear, there is no ++ operator in VB, I don't get why, but well...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With