Results 1 to 2 of 2

Thread: [2.0] Invoking methods with ref parameters

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    [2.0] Invoking methods with ref parameters

    I'm trying to call a method that takes a parameter by ref.
    The code below doesn't work. The variable 's' doesn't change after the method is called. I've stepped through the method that's called by the invoke and s definately changes within the method, but once it returns s is uneffected.
    Code:
    ParsedText =
    (string)Type.GetType(ClassName).GetMethod(
    ClassMethod,
    new Type[] { typeof(string).MakeByRefType() }).Invoke(null, new object[] { s });
    Cheers for any help!
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [2.0] Invoking methods with ref parameters

    I used this to pass a value by reference:

    Method:

    public void SomeMethod(ref int x)
    {
    ..... change value x in here
    }//


    Some other class:

    int x
    .......
    SomeMethod(ref x);

    // at this point, the changes that SomeMethod made with x is now persistent.

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