Deborah's Developer MindScape

         Tips and Techniques for Web and .NET developers.

October 11, 2009

Lambda Expressions: Func Delegates

Filed under: C#,Lambda Expressions,VB.NET @ 6:49 pm

A Func delegate encapsulates a method that returns a value. It takes up to four parameters (and this number is increased in .NET 4.0) plus the return value.

[To begin with an overview of lambda expressions, start here.]

The following signature is a Func delegate that takes two integer parameters and returns a string.

In C#:

Func<int, int, string>

In VB:

Func(Of Integer, Integer, String)

There are many examples of Func delegates.

The following code demonstrates the Sum function that sums the sales total for all customers in the list (and assumes that a Customer object has a SalesTotal property).

In C#:

var total = custList.Sum(c =>

In VB:

Dim total = custList.Sum(Function(c) _


1 Comment

  1.   Revathi — April 27, 2011 @ 2:31 am    Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2019 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs