Why I love Lambda Expressions

By Anoop Madhusudanan

Vote on HN

These are the areas I found myself using Lambdas.
To provide inline event handlers like
button.Click += (sender,args) =>
To find items in a collection
 var dogs= animals.Where(animal => animal.Type == "dog");
For iterating a collection, like
Creating a custom object
var myObj= mySource.Select(x => new {Name = x.name, Age= x.age});

Simple one line methods
Func<int, int> add = x => x + x;

For aggregate operations
double charCount = document.Sum(word => word.Length)

1 comment:

Please keep your comments clean.

© 2012. All Rights Reserved. Amazedsaint.com