如何引用由“with"创建的对象?在构造内? [英] How to refer to an object created by "with" within the construct?
本文介绍了如何引用由“with"创建的对象?在构造内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我经常使用 with
来创建一个对象并运行它的方法.它使代码看起来干净:
I often use with
to create an object and run its methods. it makes the code look clean:
With New MyObj(...)
.Prop1 = Val1
.Prop2 = Val2
.Run()
End With
但是,有时我想返回对象:
however, sometimes I'd like to return the object:
With New MyObj(...)
.Prop1 = Val1
.Prop2 = Val2
Return .Me
End With
但并非所有对象都有 Me(this)属性,那么如何在 with
中引用相关对象?
but not all objects have a Me (this) property, so how can I refer to the object in question within the with
?
推荐答案
好吧,我想答案是,只要我可以更改相关对象的定义,我就可以这样做:
well, I guess the answer is that so long as I can change the definition of the object in question I can do this:
Public Class XC
Public Self As XC = Me
End Class
With New XC()
Dim x As XC = .Self
End With
这篇关于如何引用由“with"创建的对象?在构造内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文