VB.NET Nested With statements from different scopes

后端 未结 2 1910
天涯浪人
天涯浪人 2021-01-22 09:44

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

相关标签:
2条回答
  • 2021-01-22 10:11

    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
    

    Here's a link to show how nested WITH statements can used.

    http://ideone.com/agjne

    0 讨论(0)
  • 2021-01-22 10:36
    'EXAMPLE:
    
    With New Object() {1, 2} 'With block 1
         Dim debug_1 As Object = .ToArray(0) 'Value 1 from object of block 1
             With New Object() {3, 4}  'With block 2
                     Dim debug_2 As Object = .ToArray(0)  'Value 3 from block 2
                     'How get 2 from block 1 of Object() {1, 2}?
                     '>>>
             End With
    End With
    'SOLUTION
    With New Object() {1, 2}    
         With New Object() {3, 4}.Concat(.ToArray)
              Dim debug_3 As Object = .ToArray(3)  'got value 2 from outer WITH block 1 [Object() {1, 2}]
              '---//---//---
         End With
         '---//---//---
    End With
    
    0 讨论(0)
提交回复
热议问题