-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from matthewreily/additional-aggregate-samples
Additional aggregate samples
- Loading branch information
Showing
4 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Linq; | ||
using System; | ||
|
||
namespace Aggregate | ||
{ | ||
public static class CountSample1 | ||
{ | ||
//This sample uses Count to get the number of unique factors of 300 using method syntax. | ||
// | ||
// Output: | ||
// There are 3 unique factors of 300. | ||
public static void MethodSyntaxExample() | ||
{ | ||
int[] factorsOf300 = { 2, 2, 3, 5, 5 }; | ||
|
||
int uniqueFactors = factorsOf300.Distinct().Count(); | ||
|
||
Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors); | ||
} | ||
|
||
//This sample uses Count to get the number of unique factors of 300 using query syntax. | ||
// | ||
// Output: | ||
// There are 3 unique factors of 300. | ||
public static void QuerySyntaxExample() | ||
{ | ||
int[] factorsOf300 = { 2, 2, 3, 5, 5 }; | ||
|
||
int uniqueFactors = | ||
(from f in factorsOf300 select f).Distinct().Count(); | ||
|
||
Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
public class Program | ||
{ | ||
public void Main(string[] args) | ||
{ | ||
public void Main(string[] args) | ||
{ | ||
var sample1 = new Aggregate.AggregateSample1(); | ||
sample1.MethodSyntaxExample(); | ||
Aggregate.AggregateSample1.MethodSyntaxExample(); | ||
|
||
var sample2 = new Aggregate.AggregateSample2(); | ||
sample2.MethodSyntaxExample(); | ||
} | ||
Aggregate.AggregateSample2.MethodSyntaxExample(); | ||
|
||
Aggregate.CountSample1.MethodSyntaxExample(); | ||
|
||
Aggregate.CountSample1.QuerySyntaxExample(); | ||
} | ||
} |