Tuesday, November 18, 2008

LINQ : Use of elements of string array

Again, using LINQPad:


string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

var getDigits =
from d in digits
where d[0] == 't'
select d;

getDigits.Dump();


This selects all elements in the array where the first letter is "t".

Result is:

two
three

Enjoy!

No comments: