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.

This was first published in September 2007

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.