Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the Let keyword in LINQ query syntax
By Nidhi Last Updated : November 11, 2024
VB.Net – Let Keyword in LINQ Query
In this program, we will demonstrate the Let keyword with LINQ query syntax. The Let keyword is used to projects a new range variable, allows re-use of the expression, and makes the query more readable.
Program/Source Code:
The source code to demonstrate the Let keyword in LINQ query syntax is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of Let keyword in LINQ query syntax
'VB.NET program to demonstrate the
'Let keyword in LINQ query syntax.
Imports System
Imports System.IO
Imports System.Linq
Module Module1
Public Class Employee
Public id As Integer
Public name As String
Public age As Integer
Public salary As Integer
End Class
Sub Main()
Dim empList = New List(Of Employee) From
{
New Employee() With {.id = 101, .name = "Amit", .age = 21, .salary = 5000},
New Employee() With {.id = 102, .name = "varun", .age = 22, .salary = 5500},
New Employee() With {.id = 103, .name = "vikas", .age = 23, .salary = 6000},
New Employee() With {.id = 104, .name = "Karan", .age = 21, .salary = 6700},
New Employee() With {.id = 105, .name = "Akki", .age = 26, .salary = 7500},
New Employee() With {.id = 105, .name = "Anuj", .age = 23, .salary = 8700}
}
Dim lemps = From emp In empList
Let lowercaseEmployees = emp.name.ToLower()
Where lowercaseEmployees.StartsWith("v")
Select lowercaseEmployees
Console.WriteLine("Employees: ")
For Each emp In lemps
Console.WriteLine(vbTab & emp)
Next
End Sub
End Module
Output
Employees:
varun
vikas
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains Employee class and a Main() function. The Employee class contains the data member id, name, age, and salary.
The Main() function is the entry point for the program. In the Main() function, we created a list of employees and then get the employee names that are lower case and started with "v" and then print the result on the console screen.
VB.Net LINQ Query Programs »