Lecture overview -- Keyboard shortcut: 'u'  Previous page: Multivalued delegates -- Keyboard shortcut: 'p'  Next page: Events [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 10 : 20
Object-oriented Programming in C#
Operators, Delegates, and Events
Lambda Expressions

A lambda expression in C#3.0 provides a smooth notation for anonymous functions

Anonymous method expressions in C#2.0 - delegate(...) {statements} - is very similar to lambda expressions

/user/normark/oop-csharp-1/sources/c-sharp/csharp-3/lambda-expressions/lambda-demo-with-arrays.csFive equivalent functions - from anonymous method expressions to lambda expressions. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/csharp-3/lambda-expressions/outputProgram output.


  • Lambda expression characteristics:

    • The body can be a statement block or an expression

    • Uses the operator => which has low priority and is right associative

    • May involve implicit inference of parameter types

    • Lambda expressions serve as syntactic sugar for a delegate expression