Option Explicit On
Public Class Form1
Private Sub btnAdd_Click() Handles btnAdd.Click
' Get A and B.
Dim A As Integer = Integer.Parse(txtA.Text)
Dim B As Integer = Integer.Parse(txtB.Text)
' Call the lambda function to calculate the result.
txtResult1.Text = (Function(i1 As Integer, i2 As Integer) i1 + i2)(A, B).ToString
' Call subroutine Calculate passing it the lambda function.
Dim plus = Function(i1 As Integer, i2 As Integer) i1 + i2
txtResult2.Text = Calculate(plus, A, B)
' Call subroutine Calculate passing it an inline lambda function.
txtResult3.Text = Calculate(
Function(i1 As Integer, i2 As Integer) i1 + i2,
A, B)
End Sub
' Apply a function to two values.
Private Function Calculate(ByVal F As Func(Of Integer, Integer, Integer), ByVal A As Integer, ByVal B As Integer) As String
' Call F to calculate the result.
Return F(A, B).ToString
End Function
End Class
Public Class Form1
Private Sub btnAdd_Click() Handles btnAdd.Click
' Get A and B.
Dim A As Integer = Integer.Parse(txtA.Text)
Dim B As Integer = Integer.Parse(txtB.Text)
' Call the lambda function to calculate the result.
txtResult1.Text = (Function(i1 As Integer, i2 As Integer) i1 + i2)(A, B).ToString
' Call subroutine Calculate passing it the lambda function.
Dim plus = Function(i1 As Integer, i2 As Integer) i1 + i2
txtResult2.Text = Calculate(plus, A, B)
' Call subroutine Calculate passing it an inline lambda function.
txtResult3.Text = Calculate(
Function(i1 As Integer, i2 As Integer) i1 + i2,
A, B)
End Sub
' Apply a function to two values.
Private Function Calculate(ByVal F As Func(Of Integer, Integer, Integer), ByVal A As Integer, ByVal B As Integer) As String
' Call F to calculate the result.
Return F(A, B).ToString
End Function
End Class