使用ref [英] Using ref
问题描述
从性能角度来看,使用ref语句是否明智?
?
>
谢谢!
Arjen
Hi,
Form a performance perspective, is it wise to use the ref statement as much
as possible?
Thanks!
Arjen
推荐答案
无论如何,对象本身都是通过引用传递的,所以我认为
使用ref实际上会减慢一点点(增加一个级别
的间接。
当我需要重置变量时我只使用ref指向另一个
对象。
- 史蒂夫
Arjen< bo ** ***@hotmail.com写信息
新闻:1B ****************************** **** @ microsof t.com ...
The objects themselves are passed by reference anyway, so I would think that
using "ref" would actually slow things down a tiny bit (adds one more level
of indirection.
I only use "ref" when I need to reseat the variable to point to a different
object.
- Steve
"Arjen" <bo*****@hotmail.comwrote in message
news:1B**********************************@microsof t.com...
形成绩效视角,是明智的吗?使用ref语句作为
多
尽可能?
谢谢!
Arjen
Hi,
Form a performance perspective, is it wise to use the ref statement as
much
as possible?
Thanks!
Arjen
Steve Harclerode< Li ************* @ hot.mail.comwrote:
Steve Harclerode <Li*************@hot.mail.comwrote:
对象本身无论如何通过引用传递
The objects themselves are passed by reference anyway
不,它们不是。引用通过价值。这有很大的价值。请参阅
http://pobox.com/~skeet/csharp/parameters.html
我只使用ref当我需要重置变量以指向不同的
对象时。
I only use "ref" when I need to reseat the variable to point to a different
object.
完全正确。
-
Jon Skeet - < sk *** @ pobox.com>
网站: http:// www。 pobox.com/~skeet
博客: http: //www.msmvps.com/jon_skeet
C#深度: http ://csharpindepth.com
Exactly.
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
" Jon Skeet [C#MVP]" < sk *** @ pobox.comschreef在bericht
新闻:MP ********************* @ msnews.microsoft.com 。 ..
"Jon Skeet [C# MVP]" <sk***@pobox.comschreef in bericht
news:MP*********************@msnews.microsoft.com. ..
Steve Harclerode< Li ************* @ hot.mail.comwrote:
Steve Harclerode <Li*************@hot.mail.comwrote:
>无论如何,对象本身都是通过引用传递的。
>The objects themselves are passed by reference anyway
不,他们不是。引用按值传递。有一个很大的
差异。请参阅
http://pobox.com/~skeet/csharp /parameters.html
>我只使用" ref"当我需要重置变量以指向不同的对象时。
>I only use "ref" when I need to reseat the variable to point to a
different
object.
完全正确。
-
Jon Skeet - < sk *** @ pobox.com>
网站: http:// www。 pobox.com/~skeet
博客: http: //www.msmvps.com/jon_skeet
C#深度: http ://csharpindepth.com
谢谢!
Thank you!
这篇关于使用ref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!