Mega Code Archive

 
Categories / C# Tutorial / LINQ
 

Simple Let Example

using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; public class MainClass{    public static void Main(string[] args){                Int32[] ArrayA = { 1, 2, 3, 4 };             Int32[] ArrayB = { 1, 2, 3, 4 };             var Squares = from QueryA in ArrayA                 from QueryB in ArrayB                 let TheSquare = QueryA * QueryB                 where TheSquare > 4                 select new { QueryA, QueryB, TheSquare };             foreach (var ThisSquare in Squares)                 Console.WriteLine(ThisSquare.QueryA.ToString() + " * " +                     ThisSquare.QueryB.ToString() + " = " +                     ThisSquare.TheSquare.ToString());    } }