Home > Microsoft .Net Development Tips > Visual Basic and Visual Basic .NET > VB 9 Anonymous Types help create flexible objects
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

VISUAL BASIC AND VISUAL BASIC .NET

VB 9 Anonymous Types help create flexible objects


Andrew Horne
07.29.2008
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


You can use anonymous types in Visual Basic 9.0 to create objects without specifically writing class definitions. Be aware that using anonymous types requires you to change your methods slightly when it comes to language-integrated queries (LINQs).

Anonymous types are one of several tools new within VB 9.0. True to their name, they allow developers to create objects without the need to name them or to define their class. What the developer does is input properties (in place of definitions), give them values, and decide which to call "key." The compiler takes a look at these properties and invents an appropriate class for the data type.

The input of these properties is the one area that the developer controls. Ultimately, anonymous types are a tool for developers who need more control over properties but no control over defining data type.

Another important function of these properties is deciding equality between two or more instances of different anonymous types. If the instances have properties that are equal in number and value, and if the same properties are considered "key," then you can conclude that the instances are equal.

Note that the mechanics of a LINQ query change slightly with anonymous -- as opposed to named -- types. You can choose how many columns of results you want and what order those results should appear in, but may not choose the data type.

Remember that anonymous types are useful only in certain circumstances. Anonymous types should be most effective when developers want control over properties, but don't need control over other aspects. In any case, anonymous types mark an increase in flexibility for VB 9.0. Class definition, no longer a stringent requirement, can be eliminated when necessary.

Full information can be accessed on the MSDN site's Anonymous Types page.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Visual Basic and Visual Basic .NET
Compose XML more quickly using Visual Basic 9
Virtualization keeps Legacy Apps alive
Visual Studio Team System Add-ins: Conchango Scrum for Team System and Scrum Dashboard
Book Excerpt: Sams Teach Yourself Visual Basic 2008 in 24 Hours -- Complete Starter Kit
Check out CodePlex for a ton of interesting .NET projects
Book excerpt: Murach's VB 2008
Book excerpt: Printing in Visual Basic 2005
Visual Basic 2008 and closures
WinForms development using SQL Server 2005 and Visual Basic 2005
Visual Basic 2005 and objects: Building a business object layer

Visual Basic and C# development skills
Let Microsoft StyleCop tame your wild C#
Compose XML more quickly using Visual Basic 9
Virtualization keeps Legacy Apps alive
Book Excerpt: Sams Teach Yourself Visual Basic 2008 in 24 Hours -- Complete Starter Kit
Microsoft delivers Office for Mac SP1 - will bring back VBA
Visual Basic and C# development skills Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts