User Profile

Collapse

Profile Sidebar

Collapse
ijrr
ijrr
Last Activity: Mar 18 '08, 11:25 PM
Joined: Jan 14 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • ijrr
    replied to C# ref in constructor and change in method
    in .NET
    Shashi,
    Thanks for the code. I changed it to reflect what I´m saying.
    The second print should be "Created by makeChanges()", because the object was passed as a reference in constructor. It should assign the new instance (it occurs if the new instance is created in the constructor).
    Seens C# lost the reference when it goes outside the method with ref, even if you assign the reference to a variable....
    See more | Go to post

    Leave a comment:


  • ijrr
    replied to C# ref in constructor and change in method
    in .NET
    Shashi,
    I was creating a new instance of myObj in the method. If I create in the constructor, it will reflect OK in main class. Creating in method, it doesn´t reflect in main class, even using ref in the constructor.
    I think it should, because myObj is actually a pointer to the reference of the object (using ref). New instance should be visible when returning from method....
    See more | Go to post

    Leave a comment:


  • ijrr
    started a topic C# ref in constructor and change in method
    in .NET

    C# ref in constructor and change in method

    Hello all!

    I´m passing a reference using ref to a constructor in class A.
    A a = new A(ref myObj);
    If I change values of myObj in class A, they are reflected on the main class.

    But, If I call a method like:
    a.myMethod()
    And change values of myObj (a private variable inside class A, assigned from ref by the constructor), they are not reflected on the main class.

    Any work around?...
    See more | Go to post
No activity results to display
Show More
Working...