Lambda to the slaughter
I recently discovered lambda expression at a glance I could not see where I would really use them, sufficed to say I now find myself using them all the time - who would have thought it.
using System;
using System.Collections.Generics;
namespace Example
{
class Subscribers
{
List<person> People = new List<person>()
public List<person> GetFemales()
{
return People.Where(p => p.Gender == “female”);
}
public List<person> GetMales()
{
return People.Where(p => p.Gender == “male’);
}
}
class Person
{
public string Name { get; set; }
public string Gender { get; set; }
}
}
There are lots of places that these can save time and effort and I personally find they add to the readability of my code. There are a few issues that I have come across Lambda is not very easy to debug.
Leave a comment
| Trackback
