VB.NET嵌套来自不同作用域的语句 [英] VB.NET Nested With statements from different scopes
问题描述
我想知道这是否可能.我有一个列表表(lstTable),它的表单与我试图用公共结构(ELEM_DATA)的信息填写的表单相同.我知道嵌套语句可以在相同范围内工作,但是如何使用下面的示例2做到这一点:
I am wondering if this is possible. I have a List Table (lstTable) that is on the same form that I am trying to fill in with information from a public structure (ELEM_DATA). I understand nested with statements will work if it is within the same scope but how can I do this with example 2 below:
示例1:
With me.lstTable.Items(RECORD)
.SubItems(1).text = ELEM_DATA(RECORD).name
.SubItems(2).text = ELEM_DATA(RECORD).number
end with
示例2:
With me.lstTable.Items(RECORD)
With ELEM_DATA(RECORD)
.SubItems(1).text = .name
.SubItems(2).text = .number
end with
end with
我不知道是否有可能,或者只是简单地将(.name)更改为其他名称.
I didnt know if it is possible or if it would be as simple as changing (.name) to something else.
推荐答案
嵌套的语句工作正常(请参阅有关冲突的评论).不幸的是,您不能将内部构件与内部构件一起使用.但是,由于您的外部WITH是一种引用类型,因此您可以按照注释中的建议使用局部变量来别名"它.
Nested With statements work (see comment about conflicts). Unfortunately you can't use the outer members inside the inner with. But since your outer WITH is a refernce type you could use a local variable to "alias" it as you suggest in you comment.
Dim l = me.lstTable.Items(RECORD) ' requires 2008 and option infer
With ELEM_DATA(RECORD)
l.SubItems(1).text = .name
End With
这里是显示嵌套WITH语句如何使用的链接.
Here's a link to show how nested WITH statements can used.
这篇关于VB.NET嵌套来自不同作用域的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!