Skip to content

Commit 84a116a

Browse files
author
zzzprojects
committed
Update example
Update example
1 parent b8c8682 commit 84a116a

36 files changed

+2077
-2092
lines changed

docs/pages/linq/aggregate.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,34 @@ This C# example uses the LINQ Aggregate method with a dynamic expression to crea
1818

1919
### LINQ
2020
{% highlight csharp %}
21+
private void uiAggregate_Simple_LINQ_Click(object sender, EventArgs e)
22+
{
23+
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
2124

22-
private void uiAggregate_Simple_LINQ_Click(object sender, EventArgs e)
23-
{
24-
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
25+
var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
2526

26-
var product = doubles.Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor);
27+
var sb = new StringBuilder();
2728

28-
var sb = new StringBuilder();
29+
sb.AppendLine("Total product of all numbers: {0}", product);
2930

30-
sb.AppendLine("Total product of all numbers: {0}", product);
31-
32-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
33-
}
34-
31+
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
32+
}
3533
{% endhighlight %}
3634

3735
### LINQ Execute
3836
{% highlight csharp %}
3937
private void uiAggregate_Simple_LINQ_Execute_Click(object sender, EventArgs e)
40-
{
41-
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
38+
{
39+
double[] doubles = {1.7, 2.3, 1.9, 4.1, 2.9};
4240

43-
var product = doubles.Execute<double>("Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor)");
41+
var product = doubles.Execute<double>("Aggregate((runningProduct, nextFactor) => runningProduct * nextFactor)");
4442

45-
var sb = new StringBuilder();
43+
var sb = new StringBuilder();
4644

47-
sb.AppendLine("Total product of all numbers: {0}", product);
45+
sb.AppendLine("Total product of all numbers: {0}", product);
4846

49-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
50-
}
47+
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
48+
}
5149
{% endhighlight %}
5250

5351
### Result
@@ -63,42 +61,38 @@ This C# example uses the LINQ Aggregate method with a dynamic expression to crea
6361

6462
### LINQ
6563
{% highlight csharp %}
64+
private void uiAggregate_Seed_LINQ_Click(object sender, EventArgs e)
65+
{
66+
var startBalance = 100.0;
6667

67-
private void uiAggregate_Seed_LINQ_Click(object sender, EventArgs e)
68-
{
69-
var startBalance = 100.0;
70-
71-
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
68+
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
7269

73-
var endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) => nextWithdrawal <= balance ? balance - nextWithdrawal : balance);
70+
var endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) => nextWithdrawal <= balance ? balance - nextWithdrawal : balance);
7471

75-
var sb = new StringBuilder();
72+
var sb = new StringBuilder();
7673

77-
sb.AppendLine("Ending balance: {0}", endBalance);
74+
sb.AppendLine("Ending balance: {0}", endBalance);
7875

79-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
80-
}
81-
76+
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
77+
}
8278
{% endhighlight %}
8379

8480
### LINQ Execute
8581
{% highlight csharp %}
86-
8782
private void uiAggregate_Seed_LINQ_Execute_Click(object sender, EventArgs e)
88-
{
89-
var startBalance = 100.0;
83+
{
84+
var startBalance = 100.0;
9085

91-
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
86+
int[] attemptedWithdrawals = {20, 10, 40, 50, 10, 70, 30};
9287

93-
var endBalance = attemptedWithdrawals.Execute<double>("Aggregate(startBalance, (balance, nextWithdrawal) => ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance)", new {startBalance});
88+
var endBalance = attemptedWithdrawals.Execute<double>("Aggregate(startBalance, (balance, nextWithdrawal) => ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance)", new {startBalance});
9489

95-
var sb = new StringBuilder();
90+
var sb = new StringBuilder();
9691

97-
sb.AppendLine("Ending balance: {0}", endBalance);
92+
sb.AppendLine("Ending balance: {0}", endBalance);
9893

99-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
100-
}
101-
94+
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
95+
}
10296
{% endhighlight %}
10397

10498
### Result

docs/pages/linq/all.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,49 @@ This C# example uses the LINQ All method with a dynamic expression to determine
1919
### LINQ
2020
{% highlight csharp %}
2121
private void uiAll_Simple_LINQ_Click(object sender, EventArgs e)
22-
{
23-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
22+
{
23+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
2424

25-
var onlyOdd = numbers.All(n => n % 2 == 1);
25+
var onlyOdd = numbers.All(n => n % 2 == 1);
2626

27-
var sb = new StringBuilder();
27+
var sb = new StringBuilder();
2828

29-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
29+
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
3030

31-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
32-
}
31+
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
32+
}
3333
{% endhighlight %}
3434

3535
### LINQ Dynamic
3636
{% highlight csharp %}
3737
private void uiAll_Simple_LINQ_Dynamic_Click(object sender, EventArgs e)
38-
{
39-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
38+
{
39+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
4040

41-
var onlyOdd = numbers.All(n => "n % 2 == 1");
41+
var onlyOdd = numbers.All(n => "n % 2 == 1");
4242

43-
var sb = new StringBuilder();
43+
var sb = new StringBuilder();
4444

45-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
45+
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
4646

47-
My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
48-
}
47+
My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
48+
}
4949
{% endhighlight %}
5050

5151
### LINQ Execute
5252
{% highlight csharp %}
5353
private void uiAll_Simple_LINQ_Execute_Click(object sender, EventArgs e)
54-
{
55-
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
54+
{
55+
int[] numbers = {1, 11, 3, 19, 41, 65, 19};
5656

57-
var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");
57+
var onlyOdd = numbers.Execute<bool>("All(n => n % 2 == 1)");
5858

59-
var sb = new StringBuilder();
59+
var sb = new StringBuilder();
6060

61-
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
61+
sb.AppendLine("The list contains only odd numbers: {0}", onlyOdd);
6262

63-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
64-
}
63+
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
64+
}
6565
{% endhighlight %}
6666

6767
### Result
@@ -78,55 +78,55 @@ This C# example uses the LINQ All method with a dynamic expression to return a g
7878
### LINQ
7979
{% highlight csharp %}
8080
private void uiAll_Grouped_LINQ_Click(object sender, EventArgs e)
81-
{
82-
var products = My.GetProductList();
81+
{
82+
var products = My.GetProductList();
8383

84-
var productGroups = products.GroupBy(p => p.Category)
85-
.Where(g => g.All(p => p.UnitsInStock > 0))
86-
.Select(g => new {Category = g.Key, Products = g});
84+
var productGroups = products.GroupBy(p => p.Category)
85+
.Where(g => g.All(p => p.UnitsInStock > 0))
86+
.Select(g => new {Category = g.Key, Products = g});
8787

88-
var sb = new StringBuilder();
88+
var sb = new StringBuilder();
8989

90-
My.ObjectDumper.Write(sb, productGroups, 1);
90+
My.ObjectDumper.Write(sb, productGroups, 1);
9191

92-
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
93-
}
92+
My.Result.Show(My.LinqResultType.Linq, uiResult, sb);
93+
}
9494
{% endhighlight %}
9595

9696
### LINQ Dynamic
9797
{% highlight csharp %}
9898
private void uiAll_Grouped_LINQ_Dynamic_Click(object sender, EventArgs e)
99-
{
100-
var products = My.GetProductList();
99+
{
100+
var products = My.GetProductList();
101101

102-
var productGroups = products.GroupBy(p => p.Category)
103-
.Where(g => g.All(p => "p.UnitsInStock > 0"))
104-
.Select(g => new {Category = g.Key, Products = g});
102+
var productGroups = products.GroupBy(p => p.Category)
103+
.Where(g => g.All(p => "p.UnitsInStock > 0"))
104+
.Select(g => new {Category = g.Key, Products = g});
105105

106-
var sb = new StringBuilder();
106+
var sb = new StringBuilder();
107107

108-
My.ObjectDumper.Write(sb, productGroups, 1);
108+
My.ObjectDumper.Write(sb, productGroups, 1);
109109

110-
My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
111-
}
110+
My.Result.Show(My.LinqResultType.LinqDynamic, uiResult, sb);
111+
}
112112
{% endhighlight %}
113113

114114
### LINQ Execute
115115
{% highlight csharp %}
116116
private void uiAll_Grouped_LINQ_Execute_Click(object sender, EventArgs e)
117-
{
118-
var products = My.GetProductList();
117+
{
118+
var products = My.GetProductList();
119119

120-
var productGroups = products.GroupBy(p => p.Category)
121-
.Where(g => g.Execute<bool>("All(p => p.UnitsInStock > 0)"))
122-
.Select(g => new { Category = g.Key, Products = g });
120+
var productGroups = products.GroupBy(p => p.Category)
121+
.Where(g => g.Execute<bool>("All(p => p.UnitsInStock > 0)"))
122+
.Select(g => new { Category = g.Key, Products = g });
123123

124-
var sb = new StringBuilder();
124+
var sb = new StringBuilder();
125125

126-
My.ObjectDumper.Write(sb, productGroups, 1);
126+
My.ObjectDumper.Write(sb, productGroups, 1);
127127

128-
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
129-
}
128+
My.Result.Show(My.LinqResultType.LinqExecute, uiResult, sb);
129+
}
130130
{% endhighlight %}
131131

132132
### Result

0 commit comments

Comments
 (0)