将“引用类型”作为参数与“ref”键传递给方法是否有意义?(Does it make sense to pass a “reference type” to a method as a parameter with 'ref' key? [duplicate])
可能重复: C#:引用类型变量有什么用“ref”?
嗨,
使用“ref”键将“引用类型”作为参数传递给方法是否有意义?
或者它只是废话,因为它已经是引用类型但不是值类型?
谢谢!
Possible Duplicate: C#: What is the use of “ref” for Reference-type variables?
Hi,
Does it make sense to pass a "reference type" to a method as a parameter with 'ref' key?
Or it is just nonsense as it is already a reference type but not a value type?
Thanks!
最满意答案
它允许您更改引用变量本身 ,以及它指向的对象。
如果您认为可能使变量指向方法内的不同对象(或为null ),则这是有意义的。
否则,不。
It lets you change the reference variable itself, in addition to the object it's pointing to.
It makes sense if you think you might make the variable point to a different object (or to null) inside your method.
Otherwise, no.
更多推荐
发布评论