ADVERTISEMENT
ADVERTISEMENT

VB.Net program to select specified fields using All() LINQ extension method

Here, we are going to learn how to select specified fields using All() LINQ extension method in VB.Net?
Submitted by Nidhi, on January 26, 2021

In this program, we will All() LINQ extension method to check all employees age is greater than 22 or not and then print the appropriate message on the console screen.

Program/Source Code:

The source code to select specified fields using the All() LINQ Extension method is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the 
'LINQ All() 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 = 21},
            New Employee() With {.id = 105, .name = "Akki", .age = 22},
            New Employee() With {.id = 105, .name = "Anuj", .age = 23}
        }

        Dim result As Boolean = empList.All(Function(e) e.age > 22)

        If (result = True) Then
            Console.WriteLine("All employees age is greater than 22")
        Else
            Console.WriteLine("All employees age is not greater than 22")
        End If
    End Sub
End Module

Output:

All employees age is not greater than 22
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains the Employee class and Main() function. The Employee class contains three data members id, name, and age.

The Main() function is the entry point for the program. In the Main() function we created the list of employees. Here, we checked the cage of all employees that are greater than 22 or not, and then print the appropriate message 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.