ADVERTISEMENT
ADVERTISEMENT

VB.Net program to skip given number of records from a collection using LINQ query

Here, we are going to learn how to skip given number of records from a collection using LINQ query in VB.Net?
Submitted by Nidhi, on February 02, 2021

In this program, we will use LINQ query syntax to skip employee records from the list of employees and then print results on the console screen.

Program/Source Code:

The source code to skip a given number of records from a collection using the LINQ query is given below. The given program is compiled and executed successfully.

'VB.NET program to skip given number of records 
'from a collection using 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
        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 Result = From emp In empList
                     Skip 3
                     Select emp

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

Output:

Employees:
104 Amar 21 6700
105 Akki 26 7500
105 Anuj 23 8700
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 skip the first 3 records using LINQ query syntax and then print the result 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.