At Tech Ed 2007, Amanda Silver, program manager for Visual Basic, demonstrated each of these features to Visual Basic developers. Taken together, she said, they make the release of Visual Basic 9 bigger than VB's move to the .NET Framework.
Requires Free Membership to View
When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.
Hannah Smalltree, Editorial Director
|
||||
LINQ has garnered the most attention among the new features in VB 9.0 and C# 3.0, largely because it allows developers to query anything that is IEnumerable -- objects, datasets, XML and so on.
"We took the query and the transform operations and brought them into VB, and we did it in such a way that the code you write is abstracted away from the data source you are querying over," Silver said.
LINQ offers quite a bit of support for query expressions such as aggregation, partitioning, grouping and ordering. This means that, while the compiler is busy, developers should not be, Silver said: "We do all the heavy lifting. You just need to write the query you need."
These queries, moreover, can take on complex forms. If operations are built up line by line, the compiler will call them sequentially. If a query is issued on top of the results of another query, it is not executed until the results are enumerated, and only one query is issued to the database.
Structurally, LINQ queries are modeled after TSQL queries, with one important difference -- in LINQ, From comes before Select. Ever since LINQ made its debut at PDC 2005, Silver said, the message Microsoft has heard is that "IntelliSense is way more important than staying close to SQL syntax."
Given that IntelliSense now comprises much more than just keywords, such a notion is not surprising.
|
||||
For example, thanks to Extension Methods, which are defined through attributes and applied to a module, a shared method can be applied as an instance method. In addition, when an object is created and properties are assigned to it, the compiler will infer the object's type, Silver said. Along those same lines, properties need not be specified, either, as the compiler will infer those based on the expression, she added.
These instances of type inference are, by default, turned on for new Visual Studio 2008 projects but turned off for migrated projects.
Developers should also notice that IntelliSense comes in handy when working with XML as well. Bring in an XML document, or copy and paste XML code into Visual Studio, and the IDE will infer its schema, saving it as an .xsd file. Once this file is passed into a VB project, full XML IntelliSense is available "anywhere that expression is valid in Visual Basic," Silver said.
This "functional construction," in which passing a set of arguments to a constructor subsequently passes a query result, is a significant improvement over the current methodology for XML programming, Silver added. This involves describing to the API what a developer is trying to do with the XML, which has to be done in a document.