|
-
Apr 17th, 2003, 01:07 PM
#1
Thread Starter
Hyperactive Member
reference variable?
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
-
Apr 19th, 2003, 04:48 PM
#2
-
Apr 19th, 2003, 05:07 PM
#3
Thread Starter
Hyperactive Member
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.
-
Apr 19th, 2003, 05:09 PM
#4
PowerPoster
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..
-
Apr 20th, 2003, 12:56 AM
#5
Thread Starter
Hyperactive Member
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.)
-
Apr 20th, 2003, 12:40 PM
#6
PowerPoster
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?
-
Apr 20th, 2003, 12:41 PM
#7
yay gay
look for boxing and unboxing..if i am not wrong that's the ability to turn from value to ref types and vice versa
\m/  \m/
-
Apr 20th, 2003, 01:35 PM
#8
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|