Passing a string to a method of a different class and using the altered string

Hi,

Seemingly easy question here. I want to pass a string a method of a different class, let the method do its job and return the string back to the method that called it.

i.e.

string help = "please";
DifferentMethod.Change(help);
I want the new "String" value before continuing with the next step.
e.g, Console.WriteLine("blah " + help);

Should print the altered string not "please"

My "DifferentMethod" class has a method called change. It looks like this:

public string Change(string plea)
{
does wonderful things using "plea"
return plea;
}

Thanks.



Answer this question

Passing a string to a method of a different class and using the altered string

  • Goh Wah

    Thanks. You are a legend!


  • tenaciousd

    Change the method to

    public string Change(ref string plea)
    {
    plea = "something new";
    return plea;
    }

    And call it like this:

    Change(ref help);

    --
    SvenC


  • Passing a string to a method of a different class and using the altered string