Having been playing around with C# the last few days and trying to take advantage of its “succinct” syntax I have tried to use the following trick.
Int32 _LastIndex = -1;
T[] _Array;
_Array[_LastIndex++] = obj;
Now the problem with this is that it returns the value prior to incrementing the number, so I tried…
_Array[(_LastIndex++)] = obj;
And yet the same behavior is occurring (Which has also got me a bit confused).
Could someone firstly explain why the second example (I understand why the first) doesn’t work? And is there some way of accomplishing what I am trying to do?
Surrounding the post-increment
_LastIndex++with parentheses doesn’t separate it into a distinct operation, it just changes:into:
If you want to increment before use, you need the pre-increment variant, as follows: