Skip to content

Commit a7bcfe1

Browse files
committed
Updated formatting
1 parent c23d04f commit a7bcfe1

File tree

31 files changed

+771
-568
lines changed

31 files changed

+771
-568
lines changed

README.md

Lines changed: 133 additions & 146 deletions
Large diffs are not rendered by default.

src/csharp/linq-aggregate/Program.cs

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ class Program : ProgramBase
99
{
1010
static void Main(string[] args)
1111
{
12-
//Linq73();
13-
//Linq74();
14-
//Linq76();
15-
//Linq77();
16-
//Linq78();
17-
//Linq79();
18-
//Linq80();
19-
//Linq81();
20-
//Linq82();
21-
//Linq83();
22-
//Linq84();
23-
//Linq85();
24-
//Linq86();
25-
//Linq87();
26-
//Linq88();
27-
//Linq89();
28-
//Linq90();
29-
//Linq91();
30-
//Linq92();
31-
Linq93();
12+
Linq73();
13+
// Linq74();
14+
// Linq76();
15+
// Linq77();
16+
// Linq78();
17+
// Linq79();
18+
// Linq80();
19+
// Linq81();
20+
// Linq82();
21+
// Linq83();
22+
// Linq84();
23+
// Linq85();
24+
// Linq86();
25+
// Linq87();
26+
// Linq88();
27+
// Linq89();
28+
// Linq90();
29+
// Linq91();
30+
// Linq92();
31+
// Linq93();
3232

3333
}
3434

@@ -61,7 +61,12 @@ static void Linq76()
6161
var customers = GetCustomerList();
6262

6363
var orderCounts = customers
64-
.Select(cust => new { cust.CustomerID, OrderCount = cust.Orders.Count() });
64+
.Select(cust =>
65+
new
66+
{
67+
cust.CustomerID,
68+
OrderCount = cust.Orders.Count()
69+
});
6570

6671
ObjectDumper.Write(orderCounts);
6772
}
@@ -74,7 +79,12 @@ static void Linq77()
7479

7580
var categoryCounts = products
7681
.GroupBy(prod => prod.Category)
77-
.Select(prodGroup => new { Category = prodGroup.Key, ProductCount = prodGroup.Count() });
82+
.Select(prodGroup =>
83+
new
84+
{
85+
Category = prodGroup.Key,
86+
ProductCount = prodGroup.Count()
87+
});
7888

7989
ObjectDumper.Write(categoryCounts);
8090
}
@@ -109,7 +119,12 @@ static void Linq80()
109119

110120
var categories = products
111121
.GroupBy(prod => prod.Category)
112-
.Select(prodGroup => new { Category = prodGroup.Key, TotalUnitsInStock = prodGroup.Sum(p => p.UnitsInStock) });
122+
.Select(prodGroup =>
123+
new
124+
{
125+
Category = prodGroup.Key,
126+
TotalUnitsInStock = prodGroup.Sum(p => p.UnitsInStock)
127+
});
113128

114129
ObjectDumper.Write(categories);
115130
}
@@ -144,7 +159,12 @@ static void Linq83()
144159

145160
var categories = products
146161
.GroupBy(prod => prod.Category)
147-
.Select(prodGroup => new { Category = prodGroup.Key, CheapestPrice = prodGroup.Min(p => p.UnitPrice) });
162+
.Select(prodGroup =>
163+
new
164+
{
165+
Category = prodGroup.Key,
166+
CheapestPrice = prodGroup.Min(p => p.UnitPrice)
167+
});
148168

149169
ObjectDumper.Write(categories);
150170
}
@@ -157,11 +177,12 @@ static void Linq84()
157177

158178
var categories = products.GroupBy(prod => prod.Category)
159179
.Select(prodGroup => new {prodGroup, minPrice = prodGroup.Min(p => p.UnitPrice)})
160-
.Select(x => new
161-
{
162-
Category = x.prodGroup.Key,
163-
CheapestProducts = x.prodGroup.Where(p => p.UnitPrice == x.minPrice)
164-
});
180+
.Select(x =>
181+
new
182+
{
183+
Category = x.prodGroup.Key,
184+
CheapestProducts = x.prodGroup.Where(p => p.UnitPrice == x.minPrice)
185+
});
165186

166187
ObjectDumper.Write(categories, 1);
167188
}
@@ -196,7 +217,12 @@ static void Linq87()
196217

197218
var categories = products
198219
.GroupBy(prod => prod.Category)
199-
.Select(prodGroup => new { Category = prodGroup.Key, MostExpensivePrice = prodGroup.Max(p => p.UnitPrice) });
220+
.Select(prodGroup =>
221+
new
222+
{
223+
Category = prodGroup.Key,
224+
MostExpensivePrice = prodGroup.Max(p => p.UnitPrice)
225+
});
200226

201227
ObjectDumper.Write(categories);
202228
}
@@ -209,11 +235,12 @@ static void Linq88()
209235

210236
var categories = products.GroupBy(prod => prod.Category)
211237
.Select(prodGroup => new {prodGroup, maxPrice = prodGroup.Max(p => p.UnitPrice)})
212-
.Select(x => new
213-
{
214-
Category = x.prodGroup.Key,
215-
MostExpensiveProducts = x.prodGroup.Where(p => p.UnitPrice == x.maxPrice)
216-
});
238+
.Select(x =>
239+
new
240+
{
241+
Category = x.prodGroup.Key,
242+
MostExpensiveProducts = x.prodGroup.Where(p => p.UnitPrice == x.maxPrice)
243+
});
217244

218245
ObjectDumper.Write(categories, 1);
219246
}
@@ -249,7 +276,12 @@ static void Linq91()
249276

250277
var categories = products
251278
.GroupBy(prod => prod.Category)
252-
.Select(prodGroup => new { Category = prodGroup.Key, AveragePrice = prodGroup.Average(p => p.UnitPrice) });
279+
.Select(prodGroup =>
280+
new
281+
{
282+
Category = prodGroup.Key,
283+
AveragePrice = prodGroup.Average(p => p.UnitPrice)
284+
});
253285

254286
ObjectDumper.Write(categories);
255287
}

src/csharp/linq-conversion/Program.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class Program : ProgramBase
99
{
1010
static void Main(string[] args)
1111
{
12-
//Linq54();
13-
//Linq55();
14-
//Linq56();
15-
Linq57();
12+
Linq54();
13+
// Linq55();
14+
// Linq56();
15+
// Linq57();
1616
}
1717

1818
[Category("Conversion Operators")]
@@ -21,13 +21,12 @@ static void Linq54()
2121
{
2222
double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 };
2323

24-
var sortedDoubles = doubles
25-
.OrderByDescending(d => d);
24+
var sortedDoubles = doubles.OrderByDescending(d => d);
2625

2726
var doublesArray = sortedDoubles.ToArray();
2827

2928
Console.WriteLine("Every other double from highest to lowest:");
30-
for (int d = 0; d < doublesArray.Length; d += 2)
29+
for (var d = 0; d < doublesArray.Length; d += 2)
3130
{
3231
Console.WriteLine(doublesArray[d]);
3332
}
@@ -40,8 +39,7 @@ static void Linq55()
4039
{
4140
string[] words = { "cherry", "apple", "blueberry" };
4241

43-
var sortedWords = words
44-
.OrderBy(x => x);
42+
var sortedWords = words.OrderBy(x => x);
4543

4644
var wordList = sortedWords.ToList();
4745

@@ -53,12 +51,13 @@ static void Linq55()
5351
[Description("This sample uses ToDictionary to immediately evaluate a sequence and a related key expression into a dictionary.")]
5452
static void Linq56()
5553
{
56-
var scoreRecords = new[]
57-
{
58-
new {Name = "Alice", Score = 50},
59-
new {Name = "Bob" , Score = 40},
60-
new {Name = "Cathy", Score = 45}
61-
};
54+
var scoreRecords =
55+
new[]
56+
{
57+
new {Name = "Alice", Score = 50},
58+
new {Name = "Bob" , Score = 40},
59+
new {Name = "Cathy", Score = 45}
60+
};
6261

6362
var scoreRecordsDict = scoreRecords.ToDictionary(sr => sr.Name);
6463

src/csharp/linq-element/Program.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ class Program : ProgramBase
1010
static void Main(string[] args)
1111
{
1212
//Linq58();
13-
//Linq59();
14-
//Linq61();
15-
//Linq62();
16-
Linq64(); }
13+
// Linq59();
14+
// Linq61();
15+
// Linq62();
16+
// Linq64();
17+
}
1718

1819
[Category("Element Operators")]
19-
[Description("This sample uses First to return the first matching element " +
20-
"as a Product, instead of as a sequence containing a Product.")]
20+
[Description("This sample uses First to return the first matching element as a Product, instead of as a sequence containing a Product.")]
2121
static void Linq58()
2222
{
2323
var products = GetProductList();
2424

25-
var product12 = products
26-
.Where(p => p.ProductID == 12)
27-
.First();
25+
var product12 = products.First(p => p.ProductID == 12);
2826

2927
ObjectDumper.Write(product12);
3028
}
@@ -35,17 +33,14 @@ static void Linq59()
3533
{
3634
var strings = new []{ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
3735

38-
var startsWithO = strings
39-
.First(s => s.StartsWith('o'));
36+
var startsWithO = strings.First(s => s.StartsWith('o'));
4037

4138
Console.WriteLine("A string starting with 'o': {0}", startsWithO);
4239
}
4340

4441

4542
[Category("Element Operators")]
46-
[Description(@"This sample uses FirstOrDefault to try to return the first element of the sequence
47-
unless there are no elements, in which case the default value for that type
48-
is returned. FirstOrDefault is useful for creating outer joins.")]
43+
[Description("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. FirstOrDefault is useful for creating outer joins.")]
4944
static void Linq61()
5045
{
5146
var numbers = new int[0];
@@ -56,8 +51,7 @@ static void Linq61()
5651
}
5752

5853
[Category("Element Operators")]
59-
[Description(@"This sample uses FirstOrDefault to return the first product whose ProductID is 789
60-
as a single Product object, unless there is no match, in which case null is returned.")]
54+
[Description("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.")]
6155
static void Linq62()
6256
{
6357
var products = GetProductList();
@@ -68,8 +62,7 @@ static void Linq62()
6862
}
6963

7064
[Category("Element Operators")]
71-
[Description(@"This sample uses ElementAt to retrieve the second number greater than 5
72-
from an array.")]
65+
[Description("This sample uses ElementAt to retrieve the second number greater than 5 from an array.")]
7366
static void Linq64()
7467
{
7568
var numbers = new [] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

src/csharp/linq-generation/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ class Program : ProgramBase
99
{
1010
static void Main(string[] args)
1111
{
12-
//Linq65();
13-
Linq66();
12+
Linq65();
13+
// Linq66();
1414
}
1515

1616
[Category("Generation Operators")]
17-
[Description(@"This sample uses Range to generate a sequence of numbers from 100 to 149
18-
that is used to find which numbers in that range are odd and even.")]
17+
[Description("This sample uses Range to generate a sequence of numbers from 100 to 149 that is used to find which numbers in that range are odd and even.")]
1918
static void Linq65()
2019
{
2120
var numbers = Enumerable.Range(100, 50)
22-
.Select(n => new { Number = n, OddEven = n % 2 == 1 ? "odd" : "even" });
21+
.Select(n =>
22+
new
23+
{
24+
Number = n,
25+
OddEven = n % 2 == 1 ? "odd" : "even"
26+
});
2327

2428
numbers.ForEach((n) => Console.WriteLine("The number {0} is {1}.", n.Number, n.OddEven));
2529
}

0 commit comments

Comments
 (0)