Lamada Expession VS Query Expression in Linq
Sample Ciode:
…….
List<int> list = new List<int>();
list.AddRange(new int[] { 20, 1, 4, 8, 9, 44 });
// Anonymous method to find event number
var r = list.FindAll(delegate(int i)
{
return i % 2 == 0;
}
).ToList() ;
// Linq : Lamada expression to find event number(method syntax)
var r1 = list.FindAll((i) => i % 2 == 0).Select(i => i ).ToList();
//or : select is not required if no projection
var r1 = list.FindAll((i) => i % 2 == 0).ToList();
// Linq : Query expression to find event number(query syntax)
var r2 = (from item in list
where item % 2 == 0
select item).ToList();
…….
0 Comments:
Post a Comment
<< Home