dave^2=-1

Now at davesquared.blogspot.com

Sponsors

News

Please visit davesquared.blogspot.com for new content and the most up-to-date versions of all posts.

All code and advice is provided without warranty -- use at your own risk! Opinions expressed here are my own and not that of my employer or any one else. This is just a blog! Don't take it too seriously! Despite not being too serious, this blog has a Privacy Policy, because it uses Google Analytics to see if anyone drops by.

LINQ, Lambda expressions and maths

One of the features that enables LINQ to work are the implementation of Lambda expressions. Lambda expressions are basically another way of representing a function, and are used in LINQ to pass function pointers/delegates around without the verbosity of declaring function blocks. For example:

public List GetFirstAiders() {
  List employees = getEmployees();
  return employees.FindAll(IsFirstAider);
}
public bool IsFirstAider(Employee employee) {
  return employee.IsFirstAider;
}

Using lambda expressions this becomes:

public List GetFirstAiders() {
  List employees = getEmployees();
  return employees.FindAll(e => e.IsFirstAider);
}

The (e => e.IsFirstAider) is the lambda expression that represents the old bool IsFirstAider(Employee) method. The types used in the function expressed are not explicitly mentioned, but are instead implied by the List method signature.

Anyway, the initial point of this post was to mention that Wikipedia has information on the mathematical background of lambda calculus.

This was originally posted to my previous blog. You can view the original post and any comments here.

Posted: Dec 13 2006, 10:52 AM by dtchepak | with no comments
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)