Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the LINQ Min() extension method
By Nidhi Last Updated : November 11, 2024
VB.Net – LINQ Min() Extension Method
In this program, we will use LINQ Min() extension method to find out the age of the youngest employee from the employee's list.
Program/Source Code:
The source code to demonstrate the LINQ Min() extension method is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of LINQ Min() extension method
'VB.NET program to demonstrate the
'LINQ Min() 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
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 = "Arun", .age = 22, .salary = 7000},
New Employee() With {.id = 103, .name = "Aman", .age = 23, .salary = 6000},
New Employee() With {.id = 104, .name = "Amar", .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 YoungeAge= empList.Min(Function(e) e.age)
Console.WriteLine("Age of youngest employee is: {0}", YoungeAge)
End Sub
End Module
Output
Age of youngest employee is: 21
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains an Employee class and Main() function. The Employee class contains id, name, age, and salary data members.
The Main() function is the entry point for the program. In the Main() function, We created the list of Employees and then find the age of youngest employee from employees list using LINQ Min() extension method and then print the result on the console screen.
VB.Net LINQ Query Programs »