Lambda expression in VB.NET
Here, we will see that how query operators accept a lambda expression as an argument.
Lambda expression
A lambda expression can contain expressions and statements, and can be used to create delegates or expression tree types.
Lambda expression Syntax
The lambda expression has the following basic form.
The lambda expression in C# y => y * y
The lambda expression in visual basic Function(y) y * y
All lambda expressions use the lambda operator =>, which is read as "goes to".
The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block.
For example
The above example defines the where where query operator which has the following Lambda expression Function(n) n.Length >= 5 as an argument.
Module Module1
Sub Main()
Dim names As String() = {"Rohatash", "Monu", "Ajay", "Vijay", "Ram", "Hari", "vikash", "Ram", "Vijay", "Rohatash"}
Dim filteredNames As IEnumerable(Of String) = System.Linq.Enumerable.Where(names, Function(n) n.Length >= 5)
For Each n As String In filteredNames
Console.WriteLine(n)
Next
End Sub
End Module
OUTPUT