Sunday, January 26, 2014

Lambdas and Delegates

Anonymous Methods in Action





Understanding Lambda Expressions














Assigning a Lambda to a Delegate
 

Handling Empty Parameters

Delegates that don't accept any parameters can be handled using lambdas:

Delegates in .NET

The .NET framework provides several different delegates that provide flexible options:
  1. Action - Accepts a single parameter and returns no value
  2. Func - Accepts a single parameter and return a value of type TResult

Using Action

Action can be used to call a method that accepts a single parameter of type T:












Using Func

Func supports a single parameter (T) and returns a value (TResult):











Summary

  • Lambdas provide a way to define inline methods using a concise syntax
  • The .NET Framework provides several built-in delegate types such as:
      • Action
      • Func
Please find below link of source code providing example.

No comments:

Post a Comment