VB.NET中lambda的写法

时间:2022-08-02 07:22:52

lambda 或者叫匿名方法

 '有返回值的匿名函数,func前面输入参数,最后一个输出参数
Dim func1 As Func(Of Integer, Integer) = Function(ByVal i As Integer)
Return i +
End Function
Dim func2 As Func(Of Integer, Integer, Integer) = Function(ByVal i As Integer, ByVal t As Integer)
Return i * t
End Function
Dim func3 As Func(Of Integer, Integer, String) = Function(ByVal i As Integer, ByVal t As Integer)
Return (i * t).ToString
End Function
'无返回值的函数
Dim act1 As Action(Of String) = Sub(ByVal name As String)
Console.Write("hello," + name)
End Sub
Console.WriteLine(func1.Invoke())
Console.WriteLine(func2.Invoke(, ))
Console.WriteLine(func3.Invoke(, ))
act1.Invoke("bob")