问题描述
大家好,
我将一个类的引用传递给一个表单的构造函数,比如
so:public MyForm(int count,ref Area myArea){...}
如何在构造函数之外使用myArea?我应该创建另一个
区域并将myArea分配给它(即:Area foo = myArea;)还是有一个
更好的方式?
~AF
Hello all,
I''m passing a reference to a class into the constructor of a form, like
so: public MyForm(int count, ref Area myArea) {...}
How can I use myArea outside the constructor? Should I create another
Area and assign myArea to it (ie: Area foo = myArea;) or is there a
better way?
~AF
推荐答案
不,他们不是。引用按值传递。我知道这可能比说完全解释它更容易
,但我认为它确实会对
结束造成伤害。
致OP:请参阅真的意思是,和b $ b一样,C#做什么。
-
Jon Skeet - < sk *** @ pobox。 com>
如果回复小组,请不要给我发邮件
No they''re not. References are passed by value. I know it may be easier
to say this than to explain it fully, but I think it does harm in the
end.
To the OP: see http://www.pobox.com/~skeet/csharp/parameters.html for a
full discussion about what "passing by reference" really means, and
what C# does.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
这篇关于关于通过引用传递对象的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!