VB.NET 嵌套来自不同范围的语句 [英] VB.NET Nested With statements from different scopes

查看:24
本文介绍了VB.NET 嵌套来自不同范围的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是否可能.我有一个列表 (lstTable),它与我试图用来自公共结构 (ELEM_DATA) 的信息填写的表单相同.我知道嵌套 with 语句在同一范围内会起作用,但如何使用下面的示例 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.

推荐答案

Nested With 语句有效(请参阅有关冲突的评论).不幸的是,您不能在内部使用外部成员.但是由于您的外部 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.

http://ideone.com/agjne

这篇关于VB.NET 嵌套来自不同范围的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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