CSharp examples for LINQ:where
even values displayed in sorted order
using System;//from w ww . java 2 s . co 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 // even values displayed in sorted order Console.Write("\nEven values displayed in sorted order: "); values.Where(value => value % 2 == 0) // find even integers .OrderBy(value => value) // sort remaining 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)); } }