VB.NET LINQ - Introduction

| Page Views: 60

LINQ stands for Language Intergrated Query. It is pronounced link.

Let's start by getting our feet wet with a Hello World LINQ program to query an array for documents ending with .doc extension in VB.NET.

Module Module1
    Sub Main()
        Dim documents() As String = {"Alpha Centauri in 20 years.doc", "Spaceship Design.ppt", "Project Proposal.doc", "Achieving Light Speed.doc", "Cities of the Future.pdf", "Designing a Language.pdf"}

        Dim wordDocuments = From d In documents
                          Where d.EndsWith("doc")
                          Select d
        For Each document In wordDocuments
    End Sub
End Module


Alpha Centauri in 20 years.doc
Project Proposal.doc
Achieving Light Speed.doc

Now look at this statement From d In documents Where EndsWith("doc") Select d, doesn't it look like SQL statement instead of VB.NET language syntax?

Yet it's totally valid and very powerful. This is LINQ, a technology that allows us to query data and objects in high level languages like VB.NET and C#.

LINQ introduces query into the VB.NET and C# languages as first-class citizens.

This allows the compiler to type check the LINQ queries.Moreover the LINQ is syntax highlighted and we also get intellisense suggestions.

LINQ as a technology allows developers to write strongly typed and logically structured syntax for data querying.

Before the introduction of LINQ, there was no native syntax for querying data in VB.NET and C#. In fact, LINQ was a game changer not only in the .NET world but also in the wider programming field, at least among the most commonly used programming languages.

Not only can you use LINQ to query collections, but also you can use the to query SQL databases and XML files.

Best Regards.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post