Skip to content

Syntax Guide

Lambda Expressions


This diagram shows the syntax for lambda expressions in C#
This diagram shows the syntax for lambda expressions in C#

The first example uses syntax which supports multiple lambda arguments

Comparison compare;
compare = (StockItem item1, StockItem item2) => item1.Name.CompareTo ( item2.Name );

The second example is a single lambda argument expression, in which no braces are needed ()

cs var doubleIt = x => x * 2;
  • The var keyword is used to tell the compiler to determine the type of the variable. This is useful for us in the above example because it means any type of number will be doubled and stored.

Read more about var at msdn. Read more about var at msdn.