You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updated linq docs page
- added data projection via object initializer example
- added method syntax version of linq query
- code snippet in Anonymous Types section was missing a csharp tag
- removed Auto-Implemented Properties section
* increased specificity and added ref to query page
- modified introductory line to specify what example is being referenced
- added a "hammer the point home" line after the query syntax LINQ
projection empowers us b/c we choose data that
is relevant to our class
- added link to Query Expression Syntax for Standard Query Operators
for query syntax to method syntax translation
For more information, see [Object and Collection Initializers](../../../../csharp/programming-guide/classes-and-structs/object-and-collection-initializers.md).
46
-
44
+
Continuing with our `Customer` class, assume that there is a data source called `IncomingOrders`, and that for each order with a large `OrderSize`, we would like to create a new `Customer` based off of that order. A LINQ query can be executed on this data source and use object initialization to fill a collection:
45
+
```csharp
46
+
varnewLargeOrderCustomers=fromoinIncomingOrders
47
+
whereo.OrderSize>5
48
+
selectnewCustomer { Name=o.Name, Phone=o.Phone };
49
+
```
50
+
The data source may have more properties lying under the hood than the `Customer` class such as `OrderSize`, but with object initialization, the data returned from the query is molded into the desired data type; we choose the data that is relevant to our class. As a result, we now have an `IEnumerable` filled with the new `Customer`s we wanted. The above can also be written in LINQ's method syntax:
-[Object and Collection Initializers](../../../../csharp/programming-guide/classes-and-structs/object-and-collection-initializers.md)
57
+
58
+
-[Query Expression Syntax for Standard Query Operators](../../../../csharp/programming-guide/concepts/linq/query-expression-syntax-for-standard-query-operators.md)
59
+
47
60
## Anonymous Types
48
61
An anonymous type is constructed by the compiler and the type name is only available to the compiler. Anonymous types provide a convenient way to group a set of properties temporarily in a query result without having to define a separate named type. Anonymous types are initialized with a new expression and an object initializer, as shown here:
-[Expression Trees (C#)](../../../../csharp/programming-guide/concepts/expression-trees/index.md)
71
-
72
-
## Auto-Implemented Properties
73
-
Auto-implemented properties make property-declaration more concise. When you declare a property as shown in the following example, the compiler will create a private, anonymous backing field that is not accessible except through the property getter and setter.
74
-
75
-
```csharp
76
-
publicstringName {get; set;}
77
-
```
78
-
79
-
For more information, see [Auto-Implemented Properties](../../../../csharp/programming-guide/classes-and-structs/auto-implemented-properties.md).
0 commit comments