Browse by Tags
All Tags »
Lambda (
RSS)
Lambda expressions can be assigned to a delegate variable. The lambda expression is then executed when the delegate is called. [To begin with an overview of lambda expressions, start here .] In the following example, a lambda expression is assigned to...
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...
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...
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...
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...
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...
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...
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...
The Enumerable class is new in .NET 3.5 and is part of the System.Linq namespace. It provides a set of static methods that allow you to query any object that implements IEnumerable, basically meaning any object that supports a for/each. This post focuses...
The Enumerable class is new in .NET 3.5 and is part of the System.Linq namespace. It provides a set of static methods that allow you to query any object that implements IEnumerable, basically meaning any object that supports a for/each. This post focuses...
I have an XML string as follows: <States> <State name="Wisconsin"> <Regions> <Region name="Milwaukee"> <Area...
The last several posts have provided examples of using anonymous types. This post backs up a little and provides an introduction if you are not already familiar with anonymous types. If you are familiar with anonymous types and are looking for more...
This may be more of a homework assignment for a programming class than something you would do in your applications, but it is a good example of using anonymous types, which are new in .Net 3.5 in both VB and C#. [To begin with an overview of anonymous...
Some of the collections in the Microsoft Office object models implement IEnumerable. The IEnumerable interface provides the ability to perform a for/each against the collection. With .NET 3.5, a Cast extension method of IEnumerable allows you to work...
Last night, my husband (who is also a .NET developer) asked me about sorting a DataTable by user-defined columns. (Yes, we are a pretty exciting couple!) Most developers that work with DataTables know how to sort the DataTable using a DataView.Sort. If...
Visual Studio comes with DateTimePicker and MonthCalendar controls that provide a standard looking calendar for the user to pick a date. But there are times when these controls don’t provide the features you need. For example, say you want to ask the...
Looping through a list to append strings is often more challenging than it should be. For example… In C#: string emailAddresses=string.Empty; foreach (Customer c in custList) { emailAddresses += c.EmailAddress + ";"; } In...
One of my favorite features in .NET 3.5 is lambda expressions. [To begin with an overview of lambda expressions, start here .] This example demonstrates how to use lambda expressions: To compare items in two lists and find which items in one list are...