-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
This code
int i = 0;
//++ or -- onl
i++;
++i;
i--;
--i;
//++ or -- in instruction
DoSomethingWithI(i++);
DoSomethingWithI(++i);
DoSomethingWithI(i--);
DoSomethingWithI(--i);is converted like this
Private i As Integer = 0
'++ or -- only
i += 1 'perfect
i += 1 'perfect
i -= 1 'perfect
i -= 1 'perfect
'++ or -- in instruction
DoSomethingWithI(Math.Min(Interlocked.Increment(i), i - 1))'makes questions
DoSomethingWithI(Interlocked.Increment(i))
DoSomethingWithI(Math.Max(Interlocked.Decrement(i), i + 1))
DoSomethingWithI(Interlocked.Decrement(i))-
Interlocked.Increment(i) should work if System.Threading is imported, conversion doesn't notify that.
-
In
Math.Min(Interlocked.Increment(i), i - 1)why first increment and then calcul i - 1 ?
this
Math.Min(i, Interlocked.Increment(i))does the same with one subtraction less
Math.Min(Interlocked.Increment(i), i - 1)could be obscure for beginner, convert in 2 lines mays be easier for them
DoSomethingWithI(i++);goes
DoSomethingWithI(i)
i += 1and
DoSomethingWithI(++i);goes
i += 1
DoSomethingWithI(i)Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed