So far, the queries you have seen in the previous sections returned full types. That is, the queries
returned a list of Review instances (such as the Select method), a single instance of Review
(Single, First, or Last), or a numeric value (such as Count and Average).
Quite often, however, you don’t need all the information from these objects. Figure 14-4 shows a
GridView with all the properties from the Review object. To improve the presentation of this list,
you usually want to skip properties like Body and Authorized, and instead of the genre ID you
probably want to display the genre name. Although you could tell the GridView to display only the
columns you want to see, it would be more effi cient if you were able to limit the actual data. This is
pretty easy to do with anonymous types, another language feature available in C# and VB.NET. Ananonymous type is a type whose name and members you don’t defi ne up front as you do with other
types. Instead, you construct the anonymous type by selecting data and then letting the compiler
infer the type for you. The anonymous type can only be accessed within the method that declared it,
and as such you cannot return an anonymous type from a method.
If you don’t defi ne the actual type and give it a name, how can you access the type and its properties?
This is once again done with type inference, where the compiler can see what data is assigned
to a variable and then creates a new, anonymous type on the fl y.
Creating an anonymous type is easy; instead of selecting the actual object using something like
Select review, you use the new keyword in C# and New With in Visual Basic, and then defi ne the
properties you want to select between a pair of curly braces: