lambda 或者叫匿名方法函數
1 '有返回值的匿名函數,func前面輸入參數,最後一個輸出參數 2 Dim func1 As Func(Of Integer, Integer) = Function(ByVal i As Integer) 3 Return i + 1 4 End Function 5 Dim func2 As Func(Of Integer, Integer, Integer) = Function(ByVal i As Integer, ByVal t As Integer) 6 Return i * t 7 End Function 8 Dim func3 As Func(Of Integer, Integer, String) = Function(ByVal i As Integer, ByVal t As Integer) 9 Return (i * t).ToString 10 End Function 11 '無返回值的函數 12 Dim act1 As Action(Of String) = Sub(ByVal name As String) 13 Console.Write("hello," + name) 14 End Sub 15 Console.WriteLine(func1.Invoke(4)) 16 Console.WriteLine(func2.Invoke(2, 3)) 17 Console.WriteLine(func3.Invoke(2, 3)) 18 act1.Invoke("bob")