C # implicitly updates a parameter passed to a method without a return type, and does not use or not use

This is so funny for me, obviously, the developer should have used the keyword, but I cannot believe that it even works:

public BusinessResponse<MyResultType> MyMethod(){

    BusinessResponse<MyResultType> res = new BusinessResponse<MyResultType>();
    ProcessResult(res);

    return res; //this has the values set by ProcessResult!!! How?
}

private void ProcessResult(BusinessResponse<MyResultType> result)
{
    result.State = BusinessResponseState.Success;
    //set some other stuff in the result argument
}

My colleague said that this is called a "deep link", I cannot believe that this works in C #. I would reorganize using outaka private void ProcessResult(out BusinessResponse<MyResultType> result), but I still would like to know why this code works.

UPDATE

, , , . , - #, , , processResult, , , , .

+4
2

, BusinessResponse<T> class, " " . () " " # ( ol C) 1.

, , , . , , , .

1 - . () . ( , - ), . , .

, , " ". struct s, , char, bool, int .. , , ( ). , ref out.

, ref ?

, :

public class Foo {
    public string Name { get; private set; }
    public Foo(string name) {
        Name = name;
    }
}

public class Program {

    public static void Example(ref Foo f) {
        // This will print "original"
        Console.WriteLine("Example() was given {0}", f.Name);

        // We assign a new instance to the reference which was
        // passed by reference
        f = new Foo("replacement");
    } 

    public static void Main() {
        Foo f;                       // This variable is a "reference" to a Foo

        f = new Foo("original");     // We assign a new instance to that variable

        Example(ref f);

        // This will print "replacement"
        Console.WriteLine("After calling Example(), f is {0}", f.Name);
    }

}
+9

All Articles