Results 1 to 8 of 8

Thread: reference variable?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Question 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

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    a = b = 5

    is it it?
    \m/\m/

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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.

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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..

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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.)

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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?

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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/

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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
  •  



Click Here to Expand Forum to Full Width