How could I change this code
a = 10
b = a
b = 5
to result in a=5 as well, in safe environment, if possible?
Thanks,
John
Printable View
How could I change this code
a = 10
b = a
b = 5
to result in a=5 as well, in safe environment, if possible?
Thanks,
John
a = b = 5
is it it?
Well, I thought about holding 'reference to a' in 'b', like two same pointers (unsafe).
Just as using function( ref object variable ), but without the need of function.
Not sure if I follow your question but the int type in the CTS is a value type, thefore when using in an assignment operation, the reference is not copied, the value is..
Yes and that's why I'm asking if I can somehow get the reference, like b = ref a or using some tricky function... ;)
(For example, I found out, that Application object in ASP.NET keeps refence, since any changes to variable after saving it into Application state are also still saved in that state, until the variable is reinitialized using the new keyword.)
I don't know how to do this, but I am wondering what you use this for? If you need a reference to a variable, why not use the variable itself?
look for boxing and unboxing..if i am not wrong that's the ability to turn from value to ref types and vice versa
Well the purpose is to operate with variable not known at design-time.
For example, using in recursive functions. Unfortunately, CS1510: A ref or out argument must be an lvalue - such error is for example generated while passing unboxed parameter.