Monday, March 23, 2009

LINQ ... first look

Problem: array of integers, select values less then 30, sort descending

Solution:
Compile for .Net 3.5


// Make sure you include
using System.Linq;



// declare array of integers and populate
int[] nums = { 17, 31, 10, 11, 7, 39, 41, 3 };


// use LINQ to build results
var lowNums = (from n in nums
where n < 30
orderby n descending
select n);

No comments: