Reference to reference in C#?

前端 未结 6 1582
花落未央
花落未央 2021-02-05 18:24

As we all know, C# classes object are treated as references, so what happens when you pass a reference object as a reference to a method? Say we have:

public cla         


        
6条回答
  •  别跟我提以往
    2021-02-05 19:09

    ref just creates a reference to the original value. With reference types that "value" is the location of variable's memory. When you use ref the method can now change what the original variable reference. If you then do the same with a argument that is already ref the 2nd method simply has the same reference that the first method did.

提交回复
热议问题