Support for C# 3.0 Language Features
There are various features in C# 3.0 which support LINQ. They are explained
in detail.
Chapter 1
[ 9 ]
Anonymous Types
Anonymous types are used to define strong types without defining the full class.
Anonymous types are strongly typed and checked at compile time. This type is
widely used by LINQ, because LINQ returns dynamically-shaped data, whose
type is determined by the LINQ query. In LINQ, the types are defined in
situations where the types are needed temporarily, or just once. For example, given
an ice-cream which has properties like name, flavor, ingredients, price, and fat
content, we might sometimes only need the name of the ice-cream and the price.
Anonymous type helps us to define a dynamic type containing only the name and
price of the Icecream object. This is also called shaping the result of the data being
queried into a different structure or format than the original data source.
For example, following is a class that is defined for an application, and objects
created and assigned some data to it.
Pages:
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30