34 lines
600 B
Plaintext
34 lines
600 B
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Type Closure
|
|
Private:
|
|
index As Integer
|
|
Public:
|
|
Declare Constructor(index As Integer = 0)
|
|
Declare Function Square As Integer
|
|
End Type
|
|
|
|
Constructor Closure(index As Integer = 0)
|
|
This.index = index
|
|
End Constructor
|
|
|
|
Function Closure.Square As Integer
|
|
Return index * index
|
|
End Function
|
|
|
|
Dim a(1 To 10) As Closure
|
|
|
|
' create Closure objects which capture their index
|
|
For i As Integer = 1 To 10
|
|
a(i) = Closure(i)
|
|
Next
|
|
|
|
' call the Square method on all but the last object
|
|
For i As Integer = 1 to 9
|
|
Print a(i).Square
|
|
Next
|
|
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|