syntax - Single line increment and return statement in C# -


having been playing around c# last few days , trying take advantage of "succinct" syntax have tried use following trick.

int32 _lastindex = -1;  t[] _array; _array[_lastindex++] = obj; 

now problem returns value prior incrementing number, tried...

_array[(_lastindex++)] = obj; 

and yet same behavior occurring (which has got me bit confused).

could firstly explain why second example (i understand why first) doesn't work? , there way of accomplishing trying do?

surrounding post-increment _lastindex++ parentheses doesn't separate distinct operation, changes:

_array[_lastindex++] = obj;    // _array[_lastindex] = obj; _lastindex++; 

into:

_array[(_lastindex++)] = obj;  // _array[(_lastindex)] = obj; _lastindex++; 

if want increment before use, need pre-increment variant, follows:

_array[++_lastindex] = obj;    // ++_lastindex; _array[_lastindex] = obj; 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -