You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/tutorials/exploration/csharp-7.yml
+12-48Lines changed: 12 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -54,20 +54,9 @@ items:
54
54
Put a paragraph before the note in case that's the root cause.
55
55
56
56
> [!NOTE]
57
-
> The new tuples features require the <xref:System.ValueTuple> types.
58
-
> You must add the NuGet package [`System.ValueTuple`](https://www.nuget.org/packages/System.ValueTuple/) in order to use it
59
-
> on platforms that do not include the types.
57
+
> The new tuples features require the <xref:System.ValueTuple> types. You must add the NuGet package [`System.ValueTuple`](https://www.nuget.org/packages/System.ValueTuple/) in order to use it on platforms that do not include the types.
60
58
>
61
-
> This is similar to other language features that rely on types
62
-
> delivered in the framework. Examples include `async` and `await`
63
-
> relying on the `INotifyCompletion` interface, and LINQ relying
64
-
> on `IEnumerable<T>`. However, the delivery mechanism is changing
65
-
> as .NET is becoming more platform independent. The .NET Framework
66
-
> may not always ship on the same cadence as the language compiler. When new language
67
-
> features rely on new types, those types will be available as NuGet packages when
68
-
> the language features ship. As these new types are added to the .NET Standard
69
-
> Library and delivered as part of the framework, the NuGet package requirement will
70
-
> be removed.
59
+
> This is similar to other language features that rely on types delivered in the framework. Examples include `async` and `await` relying on the `INotifyCompletion` interface, and LINQ relying on `IEnumerable<T>`. However, the delivery mechanism is changing as .NET is becoming more platform independent. The .NET Framework may not always ship on the same cadence as the language compiler. When new language features rely on new types, those types will be available as NuGet packages when the language features ship. As these new types are added to the .NET Standard Library and delivered as part of the framework, the NuGet package requirement will be removed.
71
60
72
61
C# provides a rich syntax for classes and structs that explains
73
62
your design intent. But sometimes that rich syntax requires extra
@@ -78,52 +67,31 @@ items:
78
67
The fields are not validated, and you cannot define your own methods
79
68
80
69
> [!NOTE]
81
-
> Tuples were available before C# 7.0,
82
-
> but they were inefficient and had no language support.
83
-
> This meant that tuple elements could only be referenced as
84
-
> `Item1`, `Item2` and so on. C# 7.0 introduces language support for tuples,
85
-
> which enables semantic names for the fields of a tuple using new,
86
-
> more efficient tuple types.
70
+
> Tuples were available before C# 7.0, but they were inefficient and had no language support. This meant that tuple elements could only be referenced as `Item1`, `Item2` and so on. C# 7.0 introduces language support for tuples, which enables semantic names for the fields of a tuple using new more efficient tuple types.
87
71
88
72
You can create a tuple by assigning a value to each member:
That assignment creates a tuple whose members are `Item1` and `Item2`,
93
-
which you can use in the same way as <xref:System.Tuple>
94
-
You can change the syntax to create a tuple that provides semantic
95
-
names to each of the members of the tuple:
76
+
That assignment creates a tuple whose members are `Item1` and `Item2`, which you can use in the same way as <xref:System.Tuple> You can change the syntax to create a tuple that provides semantic names to each of the members of the tuple:
The `namedLetters` tuple contains fields referred to as `Alpha` and
100
-
`Beta`. Those names exist only at compile time and are not preserved
101
-
when inspecting the tuple using reflection at runtime, for example.
80
+
The `namedLetters` tuple contains fields referred to as `Alpha` and `Beta`. Those names exist only at compile time and are not preserved when inspecting the tuple using reflection at runtime, for example.
102
81
103
-
In a tuple assignment, you can also specify the names of the fields
104
-
on the right-hand side of the assignment:
82
+
In a tuple assignment, you can also specify the names of the fields on the right-hand side of the assignment:
105
83
106
84
[!code-csharp[ImplicitNamedTuple](~/samples/snippets/csharp/new-in-7/program.cs#06_ImplicitNamedTuple "Implicitly named tuple")]
107
85
108
-
You can specify names for the fields on both the
109
-
left and right-hand side of the assignment:
86
+
You can specify names for the fields on both the left and right-hand side of the assignment:
The line above generates a warning, `CS8123`, telling you that the names on the right
114
-
side of the assignment, `Alpha` and `Beta`, are ignored because they conflict
115
-
with the names on the left side, `First` and `Second`.
90
+
The line above generates a warning, `CS8123`, telling you that the names on the right side of the assignment, `Alpha` and `Beta`, are ignored because they conflict with the names on the left side, `First` and `Second`.
116
91
117
-
The examples above show the basic syntax to declare tuples. Tuples are
118
-
most useful as return types for `private` and `internal` methods. Tuples
119
-
provide a simple syntax for those methods to return multiple discrete values:
120
-
You save the work of authoring a `class` or a `struct` that
121
-
defines the type returned. There is no need to create a new type.
92
+
The examples above show the basic syntax to declare tuples. Tuples are most useful as return types for `private` and `internal` methods. Tuples provide a simple syntax for those methods to return multiple discrete values: You save the work of authoring a `class` or a `struct` that defines the type returned. There is no need to create a new type.
122
93
123
-
Creating a tuple is more efficient and more productive.
124
-
It has a simpler, lightweight syntax to define a data structure that carries
125
-
more than one value. The example method below returns the minimum and maximum
126
-
values found in a sequence of integers:
94
+
Creating a tuple is more efficient and more productive. It has a simpler, lightweight syntax to define a data structure that carries more than one value. The example method below returns the minimum and maximum values found in a sequence of integers:
@@ -133,15 +101,11 @@ when inspecting the tuple using reflection at runtime, for example.
133
101
* You do not need to create new type.
134
102
* The language enhancements removes the need to call the <xref:System.Tuple.Create``1(``0)?displayProperty=nameWithType> methods.
135
103
136
-
The declaration for the method provides the names for the fields of the
137
-
tuple that is returned. When you call the method, the return value is a
138
-
tuple whose fields are `Max` and `Min`:
104
+
The declaration for the method provides the names for the fields of the tuple that is returned. When you call the method, the return value is a tuple whose fields are `Max` and `Min`:
139
105
140
106
[!code-csharp[CallingTupleMethod](~/samples/snippets/csharp/new-in-7/program.cs#09_CallingTupleMethod "Calling a tuple returning method")]
141
107
142
-
There may be times when you want to unpackage the members of a tuple that
143
-
were returned from a method. You can do that by declaring separate variables
144
-
for each of the values in the tuple. This is called *deconstructing* the tuple:
108
+
There may be times when you want to unpackage the members of a tuple that were returned from a method. You can do that by declaring separate variables for each of the values in the tuple. This is called *deconstructing* the tuple:
145
109
146
110
[!code-csharp[CallingWithDeconstructor](~/samples/snippets/csharp/new-in-7/program.cs#10_CallingWithDeconstructor "Deconstructing a tuple")]
0 commit comments