VB.NET中lambda的写法

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")

 

posted @ 2016-01-18 15:48  Goodpy  阅读(6812)  评论(0编辑  收藏  举报