通过引用将对象传递给另一个表单? [英] Pass an object by Reference to another form?

查看:84
本文介绍了通过引用将对象传递给另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道是否有任何方式让我通过

引用另一个表单传递一个对象?


问候

Vanessa

解决方案

Vanessa< va ***** @ eclinic。 com.sg>写道:

我想知道是否有任何方法可以通过
引用另一种形式传递一个对象?




否 - 您实际上不能通过

传递*对象*(引用类型对象)引用或值。你*可以*然后传递一个对象的引用,你可以通过价值或参考传递它。


困惑?看看
http://www.pobox .com / ~sipet / csharp / parameters.html

a中详细解释了它。不可否认,这是在C#中,但从VB.NET的角度来看,大部分都应该是可以理解的。请注意,在这种情况下,有一个表格没有特别特别的 - 它只是

另一个类,而且恰好来自

System.Windows.Forms.Form。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复群组,请不要给我发邮件


绝对。

只需将对象定义为参数通过引用形式

构造函数。在构造函数中,您将希望使其相等(将内存中的

对象位置)传递给定义为对象类型的变量

您的表单类并定义范围对于你班上的那个变量。


问候

" Vanessa" < VA ***** @ eclinic.com.sg>在留言中写道

news:eQ ************* @ TK2MSFTNGP10.phx.gbl ...


我想知道是否有任何方法让我通过
引用另一种形式传递一个对象?

问候
Vanessa



Jerry写道:

绝对。


我不知道那是什么..

只需在表格
构造函数中通过引用将对象定义为参数。在构造函数中,您需要使它相等(将内存中的
对象位置)传递给定义为表单类中对象类型的变量,并在类中定义该变量的范围。 / blockquote>


其实没有,你不必发送它ByRef..它只会加上

另一层间接的。就像乔恩所说的那样,参考变量

类型包含对实际对象的引用,并且只需发送它们就可以了。

ByVal就足够了。这样,获得'传递

对象'引用的方法/类将能够以与

原始类相同的方式到达对象。此外,人们可以争辩说,在引用类型的

变量上使用ByRef实际上降级了表现只需一个

分数。


对于OP:只需按照你的方式传递对象的引用ByVal

传递任何其他变量。


Rick


Hi,
I would like to know whether there''s any way for me to pass an object by
reference to another form?

Regards
Vanessa

解决方案

Vanessa <va*****@eclinic.com.sg> wrote:

I would like to know whether there''s any way for me to pass an object by
reference to another form?



No - you can''t actually pass an *object* (a reference-type object) by
either reference or value. You *can* however pass a reference to such
an object, and you can pass that either by value or by reference.

Confused? Have a look at
http://www.pobox.com/~skeet/csharp/parameters.html which explains it in
a lot more detail. Admittedly it''s in C#, but most of it should be
fairly understandable from a VB.NET point of view. Note that there''s
nothing particularly special about a form in this case - it''s just
another class, and one which happens to derive from
System.Windows.Forms.Form.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Absolutely.
Simply define your object as a parameter by reference in the forms
constructor. In the constructor you will want to make it equal (pass the
objects location in memory) to a variable defined as the objects type in
your forms class and define the scope for that variable within your class.

Regards
"Vanessa" <va*****@eclinic.com.sg> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...

Hi,
I would like to know whether there''s any way for me to pass an object by
reference to another form?

Regards
Vanessa



Jerry wrote:

Absolutely.
Don''t know what that was for..
Simply define your object as a parameter by reference in the forms
constructor. In the constructor you will want to make it equal (pass the
objects location in memory) to a variable defined as the objects type in
your forms class and define the scope for that variable within your class.



Actually no, you don''t have to send it "ByRef".. it''ll only add on
another layer of indirection. Like Jon said, variables of reference
types hold references to the actual objects, and sending them simply
ByVal will suffice. That way, the method/class that get''s passed the
object''s reference will be able to reach the object the same way the
original class could. Also, one can argue that using a ByRef on a
variable of reference type actually "degrades" performance by just a
fraction.

For the OP: Simply pass the object''s reference ByVal in the way you''d
pass any other variable.

Rick


这篇关于通过引用将对象传递给另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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