Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit bfaadc8

Browse files
authored
Merge branch 'master' into patch-1
2 parents 6d85ecb + 0932f13 commit bfaadc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+9197
-78
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,7 @@ MigrationBackup/
354354
# binlog files for dotnet-try
355355
**/*.binlog
356356
NuGet.config
357+
358+
# MacOS files
359+
.DS_Store
360+
**/.trydotnet-builderror
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# LINQ - Aggregators
2+
3+
*Aggregator* methods return a single value calculated from all the elements in a sequence. the aggregator methods include `Count`, `Sum`, `Min`, `Max`, `Average`, and `Aggregate`.
4+
5+
## Sum all numeric elements in a sequence
6+
7+
This sample uses `Sum` to get the total of the numbers in an array.
8+
9+
``` cs --region sum-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Sum a projection from a sequence
13+
14+
This sample uses `Sum` to get the total number of characters of all words in the array.
15+
16+
``` cs --region sum-of-projection --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## Sum all elements that are members of a group
20+
21+
This sample uses `Sum` to get the total units in stock for each product category.
22+
23+
``` cs --region grouped-sum --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
**Next: [Aggregates-Min »](./aggregates-2.md) Previous: [Aggregates »](./aggregates.md)**
27+
28+
**[Home](../README.md)**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# LINQ - Aggregators
2+
3+
*Aggregator* methods return a single value calculated from all the elements in a sequence. the aggregator methods include `Count`, `Sum`, `Min`, `Max`, `Average`, and `Aggregate`.
4+
5+
## Find the minimum of a sequence of elements
6+
7+
This sample uses `Min` to get the lowest number in an array.
8+
9+
``` cs --region min-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Find the minimum of a projection
13+
14+
This sample uses `Min` to get the length of the shortest word in an array.
15+
16+
``` cs --region min-projection --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## Find the minimum in each group
20+
21+
This sample uses `Min` to get the cheapest price among each category's products.
22+
23+
``` cs --region min-grouped --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
## Find all elements matching the minimum
27+
28+
This sample uses `Min` to get the products with the cheapest price in each category.
29+
30+
``` cs --region min-each-group --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
31+
```
32+
33+
**Next: [Aggregates-Max »](./aggregates-3.md) Previous: [Aggregates-Sum »](./aggregates-1.md)**
34+
35+
**[Home](../README.md)**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# LINQ - Aggregators
2+
3+
*Aggregator* methods return a single value calculated from all the elements in a sequence. the aggregator methods include `Count`, `Sum`, `Min`, `Max`, `Average`, and `Aggregate`.
4+
5+
## Find the maximun of a sequence of elements
6+
7+
This sample uses `Max` to get the highest number in an array.
8+
9+
``` cs --region max-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Find the maximum of a projection
13+
14+
This sample uses `Max` to get the length of the longest word in an array.
15+
16+
``` cs --region max-projection --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## Find the maximum in each group
20+
21+
This sample uses `Max` to get the most expensive price among each category's products.
22+
23+
``` cs --region max-grouped --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
## Find all elements matching the maximum
27+
28+
This sample uses `Max` to get the products with the most expensive price in each category.
29+
30+
``` cs --region max-each-group --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
31+
```
32+
33+
**Next: [Aggregates-Average »](./aggregates-4.md) Previous: [Aggregates-Min »](./aggregates-2.md)**
34+
35+
**[Home](../README.md)**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# LINQ - Aggregators
2+
3+
*Aggregator* methods return a single value calculated from all the elements in a sequence. the aggregator methods include `Count`, `Sum`, `Min`, `Max`, `Average`, and `Aggregate`.
4+
5+
## Find the average of a sequence of elements
6+
7+
This sample uses `Average` to get the average of all numbers in an array.
8+
9+
``` cs --region average-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Find the average of a projection
13+
14+
This sample uses `Average` to get the average length of the words in the array.
15+
16+
``` cs --region average-projection --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## Find the average in each group
20+
21+
This sample uses `Average` to get the average price of each category's products.
22+
23+
``` cs --region average-grouped --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
## Compute an aggregate value from all elements of a sequence
27+
28+
This sample uses `Aggregate` to create a running product on the array that calculates the total product of all elements.
29+
30+
``` cs --region aggregate-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
31+
```
32+
33+
## Compute an aggregate value from a seed value and all elements of a sequence
34+
35+
This sample uses `Aggregate` to create a running account balance that subtracts each withdrawal from the initial balance of 100, as long as the balance never drops below 0.
36+
37+
``` cs --region aggregate-seeded --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
38+
```
39+
40+
**Next: [Sequence operations »](./sequence-operations.md) Previous: [Aggregates-Min »](./aggregates-2.md)**
41+
42+
**[Home](../README.md)**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# LINQ - Aggregators
2+
3+
*Aggregator* methods return a single value calculated from all the elements in a sequence. the aggregator methods include `Count`, `Sum`, `Min`, `Max`, `Average`, and `Aggregate`.
4+
5+
## Count all elements in a sequence
6+
7+
This sample uses `Count` to get the number of unique factors of 300.
8+
9+
``` cs --region count-syntax --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Count all elements matching a condition
13+
14+
This sample uses `Count` to get the number of odd ints in the array.
15+
16+
17+
``` cs --region count-conditional --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
18+
```
19+
20+
## Count all elements nested in a query
21+
22+
This sample uses `Count` to return a list of customers and how many orders each has.
23+
24+
``` cs --region nested-count --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
25+
```
26+
27+
## Count all elements that are members of a group
28+
29+
This sample uses `Count` to return a list of categories and how many products each has.
30+
31+
``` cs --region grouped-count --source-file ../src/AggregateOperators.cs --project ../src/Try101LinqSamples.csproj
32+
```
33+
34+
**Next: [Aggregates-Sum »](./aggregates-1.md) Previous: [Quantifiers »](./generators.md)**
35+
36+
**[Home](../README.md)**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# LINQ - Conversion Operators
2+
3+
The methods `ToArray`, `ToArray`, `ToDictionary`, and `OfType` provide ways to convert LINQ results to collections.
4+
5+
## Convert to an array
6+
7+
This sample uses `ToArray` to immediately evaluate a sequence into an array.
8+
9+
``` cs --region convert-to-array --source-file ../src/Conversions.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Convert to a list
13+
14+
This sample uses `ToList` to immediately evaluate a sequence into a `List<T>`.
15+
16+
``` cs --region convert-to-list --source-file ../src/Conversions.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## Convert to a dictionary
20+
21+
This sample uses `ToDictionary` to immediately evaluate a sequence and a related key expression into a dictionary.
22+
23+
``` cs --region convert-to-dictionary --source-file ../src/Conversions.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
## Convert elements that match a type
27+
28+
This sample uses `OfType` to return only the elements of the array that are of type `double`.
29+
30+
``` cs --region convert-to-type --source-file ../src/Conversions.cs --project ../src/Try101LinqSamples.csproj
31+
```
32+
33+
**Next: [Element operations &raquo;](./elements.md) Previous: [Intersect and except set operations &raquo;](./sets-2.md)**
34+
35+
**[Home](../README.md)**

101-linq-samples/docs/elements.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# LINQ - Element Operators
2+
3+
The methods `First`, `FirstOrDefault`, and `ElementAt` provide ways to select a single element by position.
4+
5+
## Find the first element
6+
7+
This sample uses `First` to return the first matching element as a `Product`, instead of as a sequence containing a `Product`.
8+
9+
``` cs --region first-element --source-file ../src/ElementOperations.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Find the first matching element
13+
14+
This sample uses `First` to find the first element in the array that starts with 'o'.
15+
16+
``` cs --region first-matching-element --source-file ../src/ElementOperations.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
## First element of a possibly empty sequence
20+
21+
This sample uses `FirstOrDefault` to try to return the first element of the sequence, unless there are no elements, in which case the default value for that type is returned.
22+
23+
``` cs --region first-or-default --source-file ../src/ElementOperations.cs --project ../src/Try101LinqSamples.csproj
24+
```
25+
26+
## First matching element or default
27+
28+
This sample uses `FirstOrDefault` to return the first product whose `ProductID` is `789` as a single `Product` object, unless there is no match, in which case `null` is returned.
29+
30+
``` cs --region first-matching-or-default --source-file ../src/ElementOperations.cs --project ../src/Try101LinqSamples.csproj
31+
```
32+
33+
## Find element at position
34+
35+
This sample uses `ElementAt` to retrieve the second number greater than 5 from an array.
36+
37+
``` cs --region element-at --source-file ../src/ElementOperations.cs --project ../src/Try101LinqSamples.csproj
38+
```
39+
40+
**Next: [Generate sequences &raquo;](./generators.md) Previous: [Conversion operations &raquo;](./conversions.md)**
41+
42+
**[Home](../README.md)**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# LINQ - Generate elements
2+
3+
The methods `Range` and `Repeat` create sequences of integers. These can be the source sequences of queries.
4+
5+
## Create a range of numbers
6+
7+
This sample uses `Range` to generates a sequence of integral numbers within a specified range.
8+
9+
``` cs --region generate-range --source-file ../src/Generators.cs --project ../src/Try101LinqSamples.csproj
10+
```
11+
12+
## Repeat the same number
13+
14+
This sample uses `Repeat` to generates a sequence that contains one repeated value.
15+
16+
``` cs --region generate-repeat --source-file ../src/Generators.cs --project ../src/Try101LinqSamples.csproj
17+
```
18+
19+
**Next: [Quantifying operations &raquo;](./quantifiers.md) Previous: [Conversion operations &raquo;](./conversions.md)**
20+
21+
**[Home](../README.md)**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# LINQ - Grouping Operators with custom comparer
2+
3+
The `group by` and `into` can use custom comparers to separate groups.
4+
5+
These samples use the following custom comparer. It compares two strings to see if they are anagrams. (Anagrams are pairs of words formed from the same letters.)
6+
7+
``` cs --region anagram-comparer --session groupby-custom-comparer --source-file ../src/Groupings.cs --project ../src/Try101LinqSamples.csproj
8+
```
9+
10+
## Groupby with a custom comparer
11+
12+
13+
``` cs --region groupby-custom-comparer --session groupby-custom-comparer --source-file ../src/Groupings.cs --project ../src/Try101LinqSamples.csproj
14+
```
15+
16+
**Next: [Nested groupings with a custom comparer &raquo;](./groupings-3.md) Previous: [Groupings &laquo;](./groupings.md)**
17+
18+
**[Home](../README.md)**

0 commit comments

Comments
 (0)