ARTICLE

LINQ Let keyword in VB.NET

Posted by Rohatash Kumar Articles | LINQ with VB.NET April 04, 2011
Here we will see that how to declare a temporary variable inside the LinQ Query using Let keyword.
Download Files:
 
Reader Level:

Here we will see that how to declare a temporary variable inside the LinQ Query using Let keyword.

The Let Keyword

LINQ has a keyword let that allow one to create temporary variable inside the query and perform the required action. We can assign the result of manipulation to temporary variable inside query and we can use that temporary variable to another manipulation.

Using Let keyword

Taking two two integer array that is Arrayfirst, arraysecond.

Dim Arrayfirst As Integer() = New Integer() {1, 2, 3}

        Dim Arraysecond As Integer() = New Integer() {1, 2, 3}

Now using Let keyword to find square value which are greater then 4.

Dim Squares = From Queryfirst In Arrayfirst From Querysecond In Arraysecond

           Let TheSquare = Queryfirst * Querysecond

           Where TheSquare > 4 Select Queryfirst, Querysecond, TheSquare

For example

Let's take a simple example of Linq query I am using two integer array to find square and after finding the square of the integer value I will use let keyword to find square value which are greater then 4.

Module Module1

    Sub Main()

        Dim Arrayfirst As Integer() = New Integer() {1, 2, 3}

        Dim Arraysecond As Integer() = New Integer() {1, 2, 3}

        Dim Squares = From Queryfirst In Arrayfirst From Querysecond In Arraysecond

           Let TheSquare = Queryfirst * Querysecond

           Where TheSquare > 4 Select Queryfirst, Querysecond, TheSquare

        For Each ThisSquare In Squares

            Console.WriteLine(ThisSquare.TheSquare.ToString())

        Next

    End Sub

End Module

OUTPUT

let.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor