Answers for "c# call by reference"

C#
3

c# pass arg by reference

void Method(ref int refArgument)
{
  // Second param will add to int refArgument
    refArgument = refArgument + 44;
}

int number = 1;
Method(ref number);
Console.WriteLine(number);
// Output: 45
Posted by: Guest on October-26-2020
0

c# call by reference

public void Foo(Image image)
{
    // This change won't be seen by the caller: it's changing the value
    // of the parameter.
    image = Image.FromStream(...);
}

public void Foo(ref Image image)
{
    // This change *will* be seen by the caller: it's changing the value
    // of the parameter, but we're using pass by reference
    image = Image.FromStream(...);
}

public void Foo(Image image)
{
    // This change *will* be seen by the caller: it's changing the data
    // within the object that the parameter value refers to.
    image.RotateFlip(...);
}
Posted by: Guest on July-27-2021

C# Answers by Framework

Browse Popular Code Answers by Language