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).
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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.