O'Reilly logo
  • Cian Odwyer thinks this is interesting:

int[] myArray = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var evenNumbers = from i in myArray where i % 2 == 0 orderby i descending select i; foreach (int i in evenNumbers) { Debug.WriteLine(i); }

From

Cover of MCSD Certification Toolkit (Exam 70-483): Programming in C#

Note

Step 1: Array named 'myArray' declared

Step 2: Variable 'evenNumbers' declared for LINQ expression - new variable derived from 'myArray'

Step 3: 'where' clause referring to ''when each element in 'myArray' is equal to this, save result to variable 'evenNumbers' ('select' is keyword used to save result to var)

Step 4: foreach loop used to WriteLine for each member of var 'evenNumbers'