Core Concept: Lambda (C#)

A lambda is an inline anonymous function.

Does that sound like JavaScript to you? It's because JavaScript has always had lambdas, and they're awesome!

First - check out the ES5 JavaScript syntax, because it's the least cryptic. In the following example, "map" runs a function on each project and constructs an array from the results. The function itself is very simple, accepting a project and returning the project name. Thus, we get an array of project names.

var projectNames ={

Here is the newer ES6 syntax, which does the same thing:

var projectNames => {

OR shorter style that we can use because the function has ONE statement

var projectNames =>

Now the same thing in C#:

var projectNames = projects.Select((p)=>

Note - the lambda syntax, and general idea remains the same.


C# (and JavaScript) let you exchange your inline, anonymous, implicitly typed function for a normal function.

i.e. you can exchange a lambda for a normal function:

private static string getProjectName(Project p){


var projectNames = projects.Select(getProjectName);

You can even exchange a lambda for a delegate, but I'm not going to because it makes me depressed to see that syntax.

You can have async lambdas:

var projectManagerNames = projects.Select(async (p)=>{
    var u = await UserDAL.GetUserAsync(p.projectManagerId);
    return u.FullName;

You can type the lambda arguments, if you want/need:

var projectNames = projects.Select((Project p)=>;

I'm not even going to make a joke about Llamas. We were all thinking it.