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 […]
Lambda Expressions: Action Delegates
Just as the name implies, an action delegate encapsulates a method that performs an action and has no return value. It takes up to four parameters (and this number is increased in .NET 4.0). [To begin with an overview of lambda expressions, start here.] The ForEach method of the List<T> is an example of an […]
Lambda Expressions: Predicate Delegates
According to Wikipedia, a predicate is “a function which returns a Boolean value”. [To begin with an overview of lambda expressions, start here.] A predicate delegate encapsulates a method that evaluates to True or False. It takes a single parameter. The Array class Find method is an example of a predicate delegate. It takes an […]
Lambda Expressions: Syntax
This post covers the syntax for lambda expressions. It uses the customer list defined in this prior post. [To begin with an overview of lambda expressions, start here.] The first example below uses the FirstOrDefault extension method on the Enumerable object to find the first customer that matches the defined expression. The FirstOrDefault method takes […]
Delegates
A delegate is an object that holds a reference to a method with a particular parameter list and return type. It is basically like an object-oriented, type-safe function pointer. Delegates basically make it possible to treat methods as entities. You can then assign a delegate to a variable or pass it as a parameter. The […]
Lambda Expressions: Finding an Item in a Generic List
In this prior post, I detailed how to build lists of things using a generic List<T>. Once you have a list, you may need to find items in the list. There are several ways to accomplish this, but using lambda expressions is the most concise. [To begin with an overview of lambda expressions, start here.] […]
Lambda Expressions: An Introduction
My presentation at our local Code Camp was fun. I covered a lot of material and had a GREAT audience. Several people have asked for the slide information in my blog. So this is the start of several posts on lambda expressions. In addition, I wrote an article on lambda expressions that should appear in […]
Silicon Valley Code Camp
The Silicon Valley Code Camp is coming up tomorrow (October 3, 2009). I am looking forward to attending! My presentation is on Lambda expressions in C# and VB. You can find the code here. If you are interested in finding out more about this FREE code camp, check it out here. Enjoy!