ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the Where() LINQ extension method

Here, we are going to demonstrate the Where() LINQ extension method in VB.Net.
Submitted by Nidhi, on January 24, 2021

In this program, we will use Where() extension method to get the list of employees whose age between 22 to 24.

Program/Source Code:

The source code to demonstrate the Where() LINQ extension method is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the 
'Where() LINQ extension method.

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 = empList.Where(Function(s) s.age >= 22).Where(Function(s) s.age <= 24)

        Console.WriteLine("Employees ")
        For Each emp As Employee In Result
            Console.WriteLine(emp.id & " " & emp.name & " " & emp.age)
        Next
    End Sub
End Module

Output:

Employees
102 Arun 22
103 Aman 23
104 Amar 24
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 used Where() LINQ method to get the detail of employees whose age between 22 to 24. After that, we printed the employee's detail on the console screen.

VB.Net LINQ Query Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.