VB.Net program to demonstrate the 'Where' clause with 'And' operator in LINQ query

Here, we are going to demonstrate the 'Where' clause with 'And' operator in LINQ query in VB.Net.
Submitted by Nidhi, on January 24, 2021 [Last updated : March 08, 2023]

VB.Net – 'Where' Clause with 'And' Operator in LINQ Query

In this program, we will use the Where clause in LINQ query to get the list of employees whose age between 22 to 24.

Program/Source Code:

The source code to demonstrate the "Where" clause with the "And" operator in the Linq query is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of 'Where' clause with 'And' operator in LINQ query

'VB.NET program to demonstrate the 
'"Where" clause with "And" operator in LinQ query.

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
    End Class

    Sub Main()
        Dim empList = New List(Of Employee) From {
            New Employee() With {.id = 101, .name = "Amit", .age = 21},
            New Employee() With {.id = 102, .name = "Arun", .age = 22},
            New Employee() With {.id = 103, .name = "Aman", .age = 23},
            New Employee() With {.id = 104, .name = "Amar", .age = 24},
            New Employee() With {.id = 105, .name = "Akki", .age = 25}
        }

        Dim Result = From emp In empList
                     Where emp.age >= 22 And emp.age <= 24
                     Select emp.name
    
    
        Console.WriteLine("Employee Names: ")
        For Each na As String In Result
            Console.WriteLine(na)
        Next
    End Sub
End Module

Output

Employee Names:
Arun
Aman
Amar
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a class Employee and the Main() function. The Main() function is the entry point for the program.

The Employee class contains data member "id", "name" and "age". In the Main() function, We create the list of employees. Here, we got the name of the employee whose age is between 22 to 24 and printed them on the console screen.

VB.Net LINQ Query Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.