Hi all,
I've been wondering about lambda expressions for a while now.
Consider the following code
vb.net Code:
  1. Sub Main()
  2.         Dim I As Integer
  3.         SomeUselessSub(Sub()
  4.                            Dim K As Integer = I
  5.                        End Sub)
  6.  
  7.         SomeUselessSub(New Action(AddressOf DoSomething))
  8.     End Sub
  9.     Sub DoSomething()
  10.  
  11.     End Sub
  12.  
  13.     Sub SomeUselessSub(ByVal D As [Delegate])
  14.  
  15.     End Sub
Both
Code:
        SomeUselessSub(Sub()
                           Dim K As Integer = I
                       End Sub)
And
Code:
 SomeUselessSub(New Action(AddressOf DoSomething))
Are valid calls to SomeUselessSub.
But in the lambda expression I have access to all Sub Main's variables. Is it safe to use them ?