CSharp examples for LINQ:where
odd values multiplied by 10 and displayed in sorted order
using System;/*from w w w. j a va2 s . c o m*/ using System.Collections.Generic; using System.Linq; class FunctionalProgramming { static void Main() { var values = new List<int> {3, 10, 6, 1, 4, 8, 2, 5, 9, 7}; Console.Write("Original values: "); values.Display(); // call Display extension method // odd values multiplied by 10 and displayed in sorted order Console.Write( "Odd values multiplied by 10 displayed in sorted order: "); values.Where(value => value % 2 != 0) // find odd integers .Select(value => value * 10) // multiply each by 10 .OrderBy(value => value) // sort the values .Display(); // show results } } // declares an extension method static class Extensions { // extension method that displays all elements separated by spaces public static void Display<T>(this IEnumerable<T> data) { Console.WriteLine(string.Join(" ", data)); } }