Share Values Within a Query - CSharp LINQ

CSharp examples for LINQ:Select

Description

Share Values Within a Query

Demo Code


using System;//  w  w  w . j av a 2s  .  c  o m
using System.Collections.Generic;
using System.Linq;
using System.Text;

class MainClass
    {
        static void Main(string[] args)
        {
            // define a numeric data source
            int[] ds1 = { 111, 213, 317, 419, 143 };

            // perform a query that shares a calculated value
            IEnumerable<double> result1 = from e in ds1
                                      let avg = ds1.Average()
                                      where (e < avg)
                                      select (e + avg);

            Console.WriteLine("Query using shared value");
            foreach (double element in result1)
            {
                Console.WriteLine("Result element {0}", element);
            }
        }
    }

Result


Related Tutorials