Skip to content

Commit 2f2fb74

Browse files
committed
Review and update code.
Hide whitespace for this commit. It's mostly formatting changes.
1 parent e9e5b2e commit 2f2fb74

File tree

10 files changed

+71
-78
lines changed

10 files changed

+71
-78
lines changed

docs/csharp/linq/get-started/snippets/SnippetApp/Basics.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
public static class Basics
44
{
55

6-
static readonly int[] scores = [
7-
0, 30, 50, 70, 80, 85, 94, 87, 96, 88, 59, 90, 91, 85, 60, 49, 100
8-
];
6+
static readonly int[] scores =
7+
[
8+
0, 30, 50, 70, 80,
9+
85, 94, 87, 96, 88,
10+
59, 90, 91, 85, 60,
11+
49, 100
12+
];
913

1014
// <SourceData>
1115
static readonly City[] cities = [
@@ -355,7 +359,8 @@ from country in countries
355359
public static void Basics17()
356360
{
357361
string[] categories = ["brass", "winds", "percussion"];
358-
Product[] products = [
362+
Product[] products =
363+
[
359364
new Product("Trumpet", "brass"),
360365
new Product("Trombone", "brass"),
361366
new Product("French Horn", "brass"),

docs/csharp/linq/get-started/snippets/SnippetApp/Exceptions.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public static void Exceptions1()
2323
if (dataSource is not null)
2424
{
2525
// If we get here, it is safe to proceed.
26-
var query =
27-
from i in dataSource
28-
select i * i;
26+
var query = from i in dataSource
27+
select i * i;
2928

3029
foreach (var i in query)
3130
{
@@ -42,16 +41,15 @@ public static void Exceptions2()
4241
string SomeMethodThatMightThrow(string s) =>
4342
s[4] == 'C' ?
4443
throw new InvalidOperationException() :
45-
@"C:\newFolder\" + s;
44+
$"""C:\newFolder\{s}""";
4645

4746
// Data source.
4847
string[] files = ["fileA.txt", "fileB.txt", "fileC.txt"];
4948

5049
// Demonstration query that throws.
51-
var exceptionDemoQuery =
52-
from file in files
53-
let n = SomeMethodThatMightThrow(file)
54-
select n;
50+
var exceptionDemoQuery = from file in files
51+
let n = SomeMethodThatMightThrow(file)
52+
select n;
5553

5654
try
5755
{

docs/csharp/linq/get-started/snippets/SnippetApp/NullValues.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ public static class NullValues
3636
public static void NullValues1()
3737
{
3838
// <null_values_1>
39-
var query1 =
40-
from c in categories
41-
where c != null
42-
join p in products on c.ID equals p?.CategoryID
43-
select new
44-
{
45-
Category = c.Name,
46-
Name = p.Name
47-
};
39+
var query1 = from c in categories
40+
where c != null
41+
join p in products on c.ID equals p?.CategoryID
42+
select new
43+
{
44+
Category = c.Name,
45+
Name = p.Name
46+
};
4847
// </null_values_1>
4948
}
5049
}

docs/csharp/linq/get-started/snippets/SnippetApp/Program.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ static void PartsOfAQuery()
105105

106106
// 2. Query creation.
107107
// numQuery is an IEnumerable<int>
108-
var numQuery =
109-
from num in numbers
110-
where (num % 2) == 0
111-
select num;
108+
var numQuery = from num in numbers
109+
where (num % 2) == 0
110+
select num;
112111

113112
// 3. Query execution.
114113
foreach (int num in numQuery)
@@ -125,26 +124,23 @@ from num in numbers
125124
// </QueryExecution>
126125

127126
// <EagerEvaluation>
128-
var evenNumQuery =
129-
from num in numbers
130-
where (num % 2) == 0
131-
select num;
127+
var evenNumQuery = from num in numbers
128+
where (num % 2) == 0
129+
select num;
132130

133131
int evenNumCount = evenNumQuery.Count();
134132
//</EagerEvaluation>
135133

136134
//<MoreEagerEvaluation>
137-
List<int> numQuery2 =
138-
(from num in numbers
139-
where (num % 2) == 0
140-
select num).ToList();
135+
List<int> numQuery2 = (from num in numbers
136+
where (num % 2) == 0
137+
select num).ToList();
141138

142139
// or like this:
143140
// numQuery3 is still an int[]
144141

145-
var numQuery3 =
146-
(from num in numbers
147-
where (num % 2) == 0
148-
select num).ToArray();
142+
var numQuery3 = (from num in numbers
143+
where (num % 2) == 0
144+
select num).ToArray();
149145
//</MoreEagerEvaluation>
150146
}

docs/csharp/linq/get-started/snippets/SnippetApp/ReturnQueryFromMethod.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ where i > 4
1111
select i.ToString();
1212

1313
void QueryMethod2(int[] ints, out IEnumerable<string> returnQ) =>
14-
returnQ =
15-
from i in ints
16-
where i < 4
17-
select i.ToString();
14+
returnQ = from i in ints
15+
where i < 4
16+
select i.ToString();
1817

19-
int[] nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
18+
int[] nums = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
2019

2120
var myQuery1 = QueryMethod1(nums);
2221
// </return_query_from_method_1>
@@ -49,10 +48,9 @@ where i < 4
4948
// </return_query_from_method_4>
5049

5150
// <return_query_from_method_5>
52-
myQuery1 =
53-
from item in myQuery1
54-
orderby item descending
55-
select item;
51+
myQuery1 = from item in myQuery1
52+
orderby item descending
53+
select item;
5654

5755
// Execute the modified query.
5856
Console.WriteLine("\nResults of executing modified myQuery1:");

docs/csharp/linq/get-started/snippets/SnippetApp/RuntimeFiltering.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ public static class RuntimeFiltering
77
public static void RuntimeFiltering1()
88
{
99
// <runtime_filtering_1>
10-
int[] ids = [111, 114, 112];
10+
int[] ids = [ 111, 114, 112 ];
1111

12-
var queryNames =
13-
from student in students
14-
where ids.Contains(student.ID)
15-
select new
16-
{
17-
student.LastName,
18-
student.ID
19-
};
12+
var queryNames = from student in students
13+
where ids.Contains(student.ID)
14+
select new
15+
{
16+
student.LastName,
17+
student.ID
18+
};
2019

2120
foreach (var name in queryNames)
2221
{
@@ -30,7 +29,7 @@ where ids.Contains(student.ID)
3029
*/
3130

3231
// Change the ids.
33-
ids = [122, 117, 120, 115];
32+
ids = [ 122, 117, 120, 115 ];
3433

3534
// The query will now return different results
3635
foreach (var name in queryNames)

docs/csharp/linq/get-started/snippets/SnippetApp/StoreResultsOfQueryInMemory.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ public static class StoreResultsOfQueryInMemory
55
public static void StoreResultsOfQueryInMemory1()
66
{
77
// <store_results_of_query_in_memory_1>
8-
List<int> numbers = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
8+
List<int> numbers = [ 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ];
99

10-
IEnumerable<int> queryFactorsOfFour =
11-
from num in numbers
12-
where num % 4 == 0
13-
select num;
10+
IEnumerable<int> queryFactorsOfFour = from num in numbers
11+
where num % 4 == 0
12+
select num;
1413

1514
// Store the results in a new variable
1615
// without executing a foreach loop.

docs/csharp/linq/get-started/snippets/SnippetApp/TypeRelationships.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ class Customer
99
public string FirstName { get; set; }
1010
public string Phone {get; set;}
1111
}
12-
static List<Customer> customers = new List<Customer>();
12+
static List<Customer> customers = new ();
1313

1414
public static void ExplicitType()
1515
{
1616
//<ExplicitType>
17-
IEnumerable<Customer> customerQuery =
18-
from cust in customers
19-
where cust.City == "London"
20-
select cust;
17+
IEnumerable<Customer> customerQuery = from cust in customers
18+
where cust.City == "London"
19+
select cust;
2120

2221
foreach (Customer customer in customerQuery)
2322
{
@@ -29,10 +28,9 @@ from cust in customers
2928
public static void ImplicitType()
3029
{
3130
//<ImplicitType>
32-
var customerQuery2 =
33-
from cust in customers
34-
where cust.City == "London"
35-
select cust;
31+
var customerQuery2 = from cust in customers
32+
where cust.City == "London"
33+
select cust;
3634

3735
foreach(var customer in customerQuery2)
3836
{

docs/csharp/linq/get-started/snippets/SnippetApp/WriteLinqQueries.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
public class WriteLinqQueries
44
{
5-
static readonly List<int> numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0];
6-
static readonly List<int> numbers1 = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0];
7-
static readonly List<int> numbers2 = [15, 14, 11, 13, 19, 18, 16, 17, 12, 10];
5+
static readonly List<int> numbers = [ 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 ];
6+
static readonly List<int> numbers1 = [ 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 ];
7+
static readonly List<int> numbers2 = [ 15, 14, 11, 13, 19, 18, 16, 17, 12, 10 ];
88

99
public static void MethodSyntax()
1010
{
@@ -19,7 +19,9 @@ orderby num
1919
select num;
2020

2121
//Method syntax:
22-
IEnumerable<int> numQuery2 = numbers.Where(num => num % 2 == 0).OrderBy(n => n);
22+
IEnumerable<int> numQuery2 = numbers
23+
.Where(num => num % 2 == 0)
24+
.OrderBy(n => n);
2325

2426
foreach (int i in numQuery1)
2527
{
@@ -36,7 +38,7 @@ orderby num
3638
public static void WriteLinqQueries1()
3739
{
3840
// <write_linq_queries_1>
39-
List<int> numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0];
41+
List<int> numbers = [ 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 ];
4042

4143
// The query variables can also be implicitly typed by using var
4244

@@ -64,8 +66,8 @@ from item in groupingQuery
6466
public static void WriteLinqQueries2()
6567
{
6668
// <write_linq_queries_2>
67-
List<int> numbers1 = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0];
68-
List<int> numbers2 = [15, 14, 11, 13, 19, 18, 16, 17, 12, 10];
69+
List<int> numbers1 = [ 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 ];
70+
List<int> numbers2 = [ 15, 14, 11, 13, 19, 18, 16, 17, 12, 10 ];
6971

7072
// Query #4.
7173
double average = numbers1.Average();

docs/csharp/linq/get-started/snippets/SnippetApp/how-to-handle-null-values-in-query-expressions_2.cs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)