Skip to content

Commit 506be04

Browse files
Ron PetrushaBillWagner
andauthored
Apply suggestions from code review
A very thorough early review from Ron Co-Authored-By: BillWagner <wiwagn@microsoft.com>
1 parent 326b123 commit 506be04

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

docs/csharp/tutorials/exploration/csharp-7.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ items:
4040
* No need to assign an initial value.
4141
- By declaring the `out` variable where it is used in a method call, you can't accidentally use it before it is assigned.
4242
43-
The most common use for this feature will be the `Try` pattern. In this
43+
The most common use for this feature is in the `Try` pattern. In this
4444
pattern, a method returns a `bool` indicating success or failure and an
4545
`out` variable that provides the result if the method succeeds.
4646
@@ -64,20 +64,20 @@ items:
6464
> on platforms that do not include the types.
6565
>
6666
> This is similar to other language features that rely on types
67-
> delivered in the framework. Example include `async` and `await`
67+
> delivered in the framework. Examples include `async` and `await`
6868
> relying on the `INotifyCompletion` interface, and LINQ relying
6969
> on `IEnumerable<T>`. However, the delivery mechanism is changing
7070
> as .NET is becoming more platform independent. The .NET Framework
7171
> may not always ship on the same cadence as the language compiler. When new language
7272
> features rely on new types, those types will be available as NuGet packages when
73-
> the language features ship. As these new types get added to the .NET Standard
74-
> API and delivered as part of the framework, the NuGet package requirement will
73+
> the language features ship. As these new types are added to the .NET Standard
74+
> Library and delivered as part of the framework, the NuGet package requirement will
7575
> be removed.
7676
77-
C# provides a rich syntax for classes and structs that is used to explain
77+
C# provides a rich syntax for classes and structs that explains
7878
your design intent. But sometimes that rich syntax requires extra
7979
work with minimal benefit. You may often write methods that need a simple
80-
structure containing more than one data element. To support these scenarios
80+
structure containing more than one data element. To support these scenarios,
8181
*tuples* were added to C#. Tuples are lightweight data structures
8282
that contain multiple fields to represent the data members.
8383
The fields are not validated, and you cannot define your own methods
@@ -103,7 +103,7 @@ items:
103103
104104
The `namedLetters` tuple contains fields referred to as `Alpha` and
105105
`Beta`. Those names exist only at compile time and are not preserved
106-
for example when inspecting the tuple using reflection at runtime.
106+
when inspecting the tuple using reflection at runtime, for example.
107107

108108
In a tuple assignment, you can also specify the names of the fields
109109
on the right-hand side of the assignment:
@@ -116,17 +116,17 @@ items:
116116
[!code-csharp[NamedTupleConflict](~/samples/snippets/csharp/new-in-7/program.cs#07_NamedTupleConflict "Named tuple conflict")]
117117

118118
The line above generates a warning, `CS8123`, telling you that the names on the right
119-
side of the assignment, `Alpha` and `Beta` are ignored because they conflict
119+
side of the assignment, `Alpha` and `Beta`, are ignored because they conflict
120120
with the names on the left side, `First` and `Second`.
121121

122122
The examples above show the basic syntax to declare tuples. Tuples are
123123
most useful as return types for `private` and `internal` methods. Tuples
124124
provide a simple syntax for those methods to return multiple discrete values:
125125
You save the work of authoring a `class` or a `struct` that
126-
defines the type returned. There is no need for creating a new type.
126+
defines the type returned. There is no need to create a new type.
127127

128128
Creating a tuple is more efficient and more productive.
129-
It is a simpler, lightweight syntax to define a data structure that carries
129+
It has a simpler, lightweight syntax to define a data structure that carries
130130
more than one value. The example method below returns the minimum and maximum
131131
values found in a sequence of integers:
132132

@@ -136,7 +136,7 @@ items:
136136

137137
* You save the work of authoring a `class` or a `struct` that defines the type returned.
138138
* You do not need to create new type.
139-
* The language enhancements removes the need to call the <xref:System.Tuple.Create``1(``0)> methods.
139+
* The language enhancements removes the need to call the <xref:System.Tuple.Create``1(``0)?displayProperty=nameWithType> methods.
140140

141141
The declaration for the method provides the names for the fields of the
142142
tuple that is returned. When you call the method, the return value is a
@@ -174,7 +174,7 @@ items:
174174
- title: Use discards to select needed members
175175
durationInMinutes: 2
176176
content: |
177-
Often when deconstructing a tuple or calling a method with `out` parameters, you're forced to define a variable whose value you don't care about and don't intend to use. C# adds support for *discards* to handle this scenario. A discard is a write-only variable whose name is `_` (the underscore character); you can assign all of the values that you intend to discard to the single variable. A discard is like an unassigned variable; apart from the assignment statement, the discard can't be used in code.
177+
Often when deconstructing a tuple or calling a method with `out` parameters, you're forced to define a variable whose value you don't care about and don't intend to use. C# adds support for *discards* to handle this scenario. A discard is a write-only variable whose name is `_` (the underscore character); you can assign all of the values that you intend to discard to the single variable. A discard is like an unassigned variable; apart from the assignment, the discard can't be used in code.
178178
179179
Discards are supported in the following scenarios:
180180
@@ -186,7 +186,7 @@ items:
186186
187187
* As a standalone identifier when you want to explicitly identify the value of an assignment as a discard.
188188
189-
The following example defines a `QueryCityDataForYears` method that returns a 6-tuple that contains a data for a city for two different years. The method call in the example is concerned only with the two population values returned by the method and so treats the remaining values in the tuple as discards when it deconstructs the tuple.
189+
The following example defines a `QueryCityDataForYears` method that returns a 6-tuple that contains data for a city for two different years. The method call in the example is concerned only with the two population values returned by the method and so treats the remaining values in the tuple as discards when it deconstructs the tuple.
190190
191191
[!code-csharp[Tuple-discard](~/samples/snippets/csharp/programming-guide/deconstructing-tuples/discard-tuple1.cs)]
192192
@@ -197,16 +197,16 @@ items:
197197
content: |
198198
*Pattern matching* is a feature that allows you to implement method dispatch on
199199
properties other than the type of an object. You're probably already familiar
200-
with method dispatch based on the type of an object. In Object Oriented programming,
200+
with method dispatch based on the type of an object. In object oriented programming,
201201
virtual and override methods provide language syntax to implement method dispatching
202-
based on an object's type. Base and Derived classes provide different implementations.
202+
based on an object's type. Base and derived classes provide different implementations.
203203
Pattern matching expressions extend this concept so that you can easily
204204
implement similar dispatch patterns for types and data elements that are
205205
not related through an inheritance hierarchy.
206206
207207
Pattern matching supports `is` expressions and `switch` expressions. Each
208208
enables inspecting an object and its properties to determine if that object
209-
satisfies the sought pattern. You use the `when` keyword to specify additional
209+
satisfies the desired pattern. You use the `when` keyword to specify additional
210210
rules to the pattern.
211211
212212
### `is` expression
@@ -299,18 +299,18 @@ items:
299299
content: |
300300
This feature enables algorithms that use and return references
301301
to variables defined elsewhere. One example is working with
302-
large matrices, and finding a single location with certain
302+
large matrices and finding a single location with certain
303303
characteristics. One method would return the two indices for
304304
a single location in the matrix:
305305
306306
[!code-csharp[FindReturningIndices](~/samples/snippets/csharp/new-in-7/MatrixSearch.cs#20_FindReturningIndices "Find returning indices")]
307307
308308
There are many issues with this code. First of all, it's a public
309-
method that's returning a tuple. The language supports this, but
310-
user defined types (either classes or structs) are preferred
309+
method that returns a tuple. The language supports this, but
310+
user-defined types (either classes or structs) are preferred
311311
for public APIs.
312312
313-
Second, this method is returning the indices to the item in the matrix.
313+
Second, this method returns the indices to the item in the matrix.
314314
That leads callers to write code that uses those indices to dereference
315315
the matrix and modify a single element:
316316
@@ -323,7 +323,7 @@ items:
323323
Let's walk through a series of changes to demonstrate the ref local feature
324324
and show how to create a method that returns a reference to internal storage.
325325
Along the way, you'll learn the rules of the ref return and ref local feature that
326-
protects you from accidentally misusing it.
326+
protect you from accidentally misusing it.
327327
328328
Start by modifying the `Find` method declaration so that it returns a `ref int`
329329
instead of a tuple. Then, modify the return statement so it returns the value
@@ -369,11 +369,11 @@ items:
369369
370370
[!code-csharp[AssignRefReturn](~/samples/snippets/csharp/new-in-7/program.cs#24_AssignRefReturn "Assign ref return")]
371371
372-
Now, the second `WriteLine` statement in the example above will print
372+
Now, the second `WriteLine` statement in the example above prints
373373
out the value `24`, indicating that the storage in the matrix has been
374374
modified. The local variable has been declared with the `ref` modifier,
375375
and it will take a `ref` return. You must initialize a `ref` variable when
376-
it is declared, you cannot split the declaration and the initialization.
376+
it is declared; you cannot split the declaration and the initialization.
377377
378378
The C# language has three other rules that protect you from misusing
379379
the `ref` locals and returns:
@@ -399,7 +399,7 @@ items:
399399
Many designs for classes include methods that are called from only
400400
one location. These additional private methods keep each method small
401401
and focused. However, they can make it harder to understand a class
402-
when reading it the first time. These methods must be understood
402+
when reading it the first time, since these methods are understood
403403
outside of the context of the single calling location.
404404
405405
For those designs, *local functions* enable you to declare methods
@@ -461,9 +461,9 @@ items:
461461
> [!NOTE]
462462
> Some of the designs that are supported by local functions
463463
> could also be accomplished using *lambda expressions*. Those
464-
> interested can [read more about the differences](../../local-functions-vs-lambdas.md)
464+
> interested can [read more about the differences](../../local-functions-vs-lambdas.md).
465465
466-
- title: Throw expressions more concise error reporting
466+
- title: Throw expressions allow more concise error reporting
467467
durationInMinutes: 2
468468
content: |
469469
In C#, `throw` has always been a statement. Because `throw` is a statement,

0 commit comments

Comments
 (0)