Using REF & OUT keywords with Passing by Reference & Passing by Value in C#

前端 未结 7 653
南笙
南笙 2021-01-12 06:32

Here is what I understand so far:

PASS BY VALUE

Passing by value means a copy of an argument is passed. Changes to that copy do not change the original.

7条回答
  •  孤独总比滥情好
    2021-01-12 07:06

    If you understand c++ maybe this will help you:

    void Foo(Bar) {} // pass by value c# (if it's a value type ;))
    void Foo(Bar) {} // c++
    
    void Foo(Bar) {} // pass by reference c# (if it's a reference type ;))
    void Foo(Bar&) {} // c++
    
    void Foo(ref Bar) {} // c#
    void Foo(Bar*) // c++
    
    void Foo(out Bar) {} // c#
    void Foo(Bar**) {} // c++ (the contents of *Bar needs to be filled up)
    

提交回复
热议问题