Problem solve Get help with specific problems with your technologies, process and projects.

Visual Basic 2008 and closures

In Visual Basic 2008, closures let programmers access an environment from more than one function. The VB team recently blogged about closures and how they work.

Among Visual Basic 2008's new features is the concept of closures. These allow programmers to access environments like locals, parameters and methods from more than one function. As Jared Parsons, a developer on the Visual Basic compiler and debugger, put it in a recent blog entry, "Closures are the underpinnings for several new features in Visual Basic [2008] They are part of the guts of Lambda and Query expressions." 

Parsons recently penned a five-part series that introduces programmers to closures in Visual Basic 2008.

Closures in VB, Part 1 explains how the compiler is able to make a variable available to more than one function. It is a process called "lifting the variable," Parsons notes.

Closures in VB, Part 2: Method Calls looks at the two types of method calls that closures tend to handle -- those that share a method or methods on a module and those that instantiate members of a class.

Closures in VB, Part 3: Scope discusses what happens when variables are lifted from different scopes. "The answer is that one closure class will be created for every unique scope where a lifted variable is declared and all of the variables in that scope that are lifted will be placed in that closure," Parsons indicates.

More on Visual Basic 2008

LINQ and XML programming in
Visual Basic 2008

How Visual Basic 2008, Windows Vista appeal to the Visual Basic 6 developer

Closures in VB, Part 4: Variable Lifetime shows how, and why, the lifetime of a variable is tied to its scope. This was done so Visual Basic 2008 could support lambda expressions, he states.

Closures in VB, Part 5: Looping goes into some of the "unintended consequences" programmers may encounter when simultaneously using looping structures and lambda expressions and explains how to combat these problems.

Finally, for more insight into the new features of VB 2008, check out the Visual Basic 2008 tag on the VB Team blog.

Next Steps

Visual Basic language apps find new life through automated conversion

Dig Deeper on .NET Framework 3.5 and Visual Studio 2008 development

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.