In C++ I can do this:
int flag=0,int1=0,int2=1;
int &iRef = (flag==0?int1:int2);
iRef +=1;
with the effect that int1 gets incremented.
I have to modify some older c# code and it would be really helpful if I could do something similar, but I’m thinking … maybe not. Anybody?
You can do it – or at least something very similar to what you want – but it’s probably best to find another approach. For example, you can wrap the integers inside a simple reference type.
If you still want to do it, see the
Ref<T>class posted by Eric Lippert here:Output: