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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM