Why use the 'ref' keyword when passing an object?

后端 未结 11 1706
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:45

If I am passing an object to a method, why should I use the ref keyword? Isn\'t this the default behaviour anyway?

For example:

class Program
{
    s         


        
11条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:35

    Ref denotes whether the function can get its hands on the object itself, or only on its value.

    Passing by reference is not bound to a language; it's a parameter binding strategy next to pass-by-value, pass by name, pass by need etc...

    A sidenote: the class name TestRef is a hideously bad choice in this context ;).

提交回复
热议问题