Chapter 5

Advanced Language Constructs

What's in this chapter?

Using and Understanding Lambda Expressions

An Easy Way to Perform Tasks Asynchronously

Working with Custom Iterators

Wrox.com Code Downloads for this Chapter

The wrox.com code download for this chapter is found at www.wrox.com/remtitle.cgi?isbn=9781118314456 on the Download Code tab. The code is in the chapter 5 download and follows the single project sample application first discussed in Chapter 1, with some minor updates.

With any language, developers are typically provided with multiple ways to perform a given action. Some of these methods are easier and more efficient than others. One cause of this is simple growing pains. As a language evolves and grows, older ways of performing some functionality are replaced by more robust, efficient, and typically easier methodologies.

This is no different with Visual Basic 2012, which has many new features and improvements. Some of these come from its aforementioned growth as a language, while some can be attributed to its close relationship with C#. While C# may gain some new features and improvements first, Visual Basic is usually not far behind.

The focus of this chapter is to dive into several language features of Visual Basic that provide more advanced functionality. These features are deeply rooted into the framework and have very widespread uses, making them capable of fulfilling many needs. These features can be used to improve the overall appearance and flow of an application or decrease development time.

The first feature covered, Lambda Expressions, is not new to Visual Basic 2012 but deserves to be called out due to its many uses. A Lambda Expression is a specialized delegate that can be referred to as inline function. They are a core part of Language Integrated Query (LINQ), which is covered in depth in Chapters 8.

The second feature covered is brand-new to Visual Basic 2012 and one of the more exciting and anticipated for any developer who has had to work with asynchronous operations. The core to this feature is the new Async and Await keywords. While Chapter 19 dives into the gritty details of performing asynchronous operations on background threads and managing them, this chapter will tell you how much of that work can now be greatly simplified by using these two new keywords.

Finally, this chapter will conclude by covering another new feature of Visual Basic 2012 known as Iterators. C# has had iterators for a few versions now, and Visual Basic has finally caught up. They provide developers with a powerful and easy way to customize how iterated data is returned to the developer or user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset