How to use an anonymous function in VB.NET

1 Answer

0 votes
Imports System

Module Program
    Sub Main()
        ' Anonymous function (lambda) that takes two integers and returns their sum.
        ' Function(a, b) a + b  → this is VB.NET's concise lambda syntax.
        Dim add As Func(Of Integer, Integer, Integer) =
            Function(a As Integer, b As Integer) a + b

        ' Use the anonymous function
        Dim result As Integer = add(10, 20)

        Console.WriteLine(result)
    End Sub
End Module

	

' run:
'
' 30
'

 



answered 1 day ago by avibootz
...