Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Lambda expressions can be used where delegates are valid. They can be converted to compatible delegate types, but not to any other type. For example, you can define a delegate type and assign a lambda expression to it, or send a lambda expression as the argument to a Func<TResult> parameter. These examples are shown in the following code.
Module Module1
Delegate Function FunDel(ByVal m As Integer) As Boolean
Sub Main()
' Assign a lambda expression to a function delegate.
Dim negative As FunDel = Function(n As Integer) n < 0
Console.WriteLine(negative(-3))
' Send a lambda as the argument to a delegate parameter.
Dim numbers() As Integer = {3, 4, 2, 8, 1, 0, 9, 13, 42}
Dim evens = numbers.Where(Function(n) n Mod 2 = 0)
For Each even In evens
Console.WriteLine(even)
Next
End Sub
End Module
Error ID: BC36625