VB.NET LINQ - Introduction


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
            Console.WriteLine(document)
        Next
        Console.ReadLine()
    End Sub
End Module

Result

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. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think

Dear readers drop us your comments below. We are building a community of students and learners. Start by dropping us your suggestions below. What tutorials do you want us to do for example? Where can we improve? What are some awesome resources out there? Do you have any code you want to share with us?
By the way that example or snippet you have lying in your computer can really help beginner programmers. We can share it here with other students.

Previous Post Next Post