是否有意义传递一个"引用类型"的方法,与“参考”键参数? [英] Does it make sense to pass a "reference type" to a method as a parameter with 'ref' key?

查看:169
本文介绍了是否有意义传递一个"引用类型"的方法,与“参考”键参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/961717/c-what-is-the-use-of-ref-for-reference-type-variables">C#:什么是使用&ldquo;参考&rdquo;的为引用类型变量?

您好,

是否有意义传递一个引用类型的方法,与裁判键?

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?

谢谢!

推荐答案

这是有道理的,如果你认为你可能把这些变量指向一个不同的对象(或)的方法内。

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.

否则,没有。

这篇关于是否有意义传递一个&QUOT;引用类型&QUOT;的方法,与“参考”键参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆