将“引用类型”作为参数与“ref”键传递给方法是否有意义?(Does it make sense to pass a “reference type” to a method as a paramet

编程入门 行业动态 更新时间:2024-10-28 09:23:36
将“引用类型”作为参数与“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.

更多推荐

本文发布于:2023-08-03 08:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有意义   参数   类型   方法   sense

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!