Skip to content

Commit d7b5b60

Browse files
authored
fixing code snippet references (dotnet#2874)
* fixing code snippet references * fixed formatting issues
1 parent 3a25c1c commit d7b5b60

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docs/csharp/deconstruct.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Deconstructing tuples and other types | Microsoft Docs
3-
description: Learn how to deconstruct tuples and other types
4-
keywords: .NET, .NET Core, C#0
2+
title: Deconstructing tuples and other types
3+
description: Learn how to deconstruct tuples and other types.
4+
keywords: .NET,.NET Core,C#
55
author: rpetrusha
66
ms-author: ronpet
77
ms.date: 07/18/2016
@@ -11,7 +11,6 @@ ms.technology: devlang-csharp
1111
ms.devlang: csharp
1212
ms.assetid: 0b0c4b0f-4a47-4f66-9b8e-f5c63b195960
1313
---
14-
1514
# Deconstructing tuples and other types #
1615

1716
A tuple provides a light-weight way to retrieve multiple values from a method call. But once you retrieve the tuple, you have to handle its individual elements. Doing this on an element-by-element basis is cumbersome, as the following example shows. The `QueryCityData` method returns a 3-tuple, and each of its elements is assigned to a variable in a separate operation.
@@ -38,22 +37,22 @@ There are two ways to deconstruct a tuple:
3837

3938
- You can use the `var` keyword so that C# infers the type of each variable. You place the `var` keyword outside of the parentheses. The following example uses type inference when deconstructing the 3-tuple returned by the `QueryCityData` method.
4039

41-
[!code-csharp[Deconstruction-Infer](../../samples/snippets/csharp/programming-guide/deconstructing-tuples/deconstruct-tuple3.cs#1)]
40+
[!code-csharp[Deconstruction-Infer](../../samples/snippets/csharp/programming-guide/deconstructing-tuples/deconstruct-tuple3.cs#1)]
4241

4342
You can also use the `var` keyword individually with any or all of the variable declarations inside the parentheses.
4443

45-
[!code-csharp[Deconstruction-Infer-Some](../../samples/snippets/csharp/programming-guide/deconstructing-tuples/deconstruct-tuple4.cs#1)]
44+
[!code-csharp[Deconstruction-Infer-Some](../../samples/snippets/csharp/programming-guide/deconstructing-tuples/deconstruct-tuple4.cs#1)]
4645

4746
This is cumbersome and is not recommended.
4847

4948
Note that you cannot specify a specific type outside the parentheses even if every field in the tuple has the
50-
same type. This generates compiler error CS8136, "`var (...)` form disallows a specific type for `var`.
49+
same type. This generates compiler error CS8136, "Deconstruction 'var (...)' form disallows a specific type for 'var'.".
5150

5251
Note that you must also assign each element of the tuple to a variable. If you omit any elements, the compiler generates error CS8132, "Cannot deconstruct a tuple of 'x' elements into 'y' variables."
5352

5453
## Deconstructing tuple elements with discards
5554

56-
Often when deconstructing a tuple, you're interested in the values of only some elements. Starting with C# 7, you can take advantage of C#'s support for *discards*, which are write-only variables whose values you've chosen to ignore. A discard is designated by an underscore character ("_") in an assignment. You can discard as many values as you like; all are represented by the single discard, `_`.
55+
Often when deconstructing a tuple, you're interested in the values of only some elements. Starting with C# 7, you can take advantage of C#'s support for *discards*, which are write-only variables whose values you've chosen to ignore. A discard is designated by an underscore character ("\_") in an assignment. You can discard as many values as you like; all are represented by the single discard, `_`.
5756

5857
The following example illustrates the use of tuples with discards. The `QueryCityDataForYears` method returns a 6-tuple with the name of a city, its area, a year, the city's population for that year, a second year, and the city's population for that second year. The example shows the change in population between those two years. Of the data available from the tuple, we're unconcerned with the city area, and we know the city name and the two dates at design-time. As a result, we're only interested in the two population values stored in the tuple, and can handle its remaining values as discards.
5958

@@ -85,7 +84,7 @@ The overloaded `Deconstruct` method in the following example illustrates one pos
8584

8685
## Deconstructing a user-defined type with discards
8786

88-
Just as you do with [tuples](#deconstructing-tuple-elements-with-discards), you can use discards to ignore selected items returned by a `Deconstruct` method. Each discard is defined by a variable named "_", and a single deconstruction operation can include multiple discards.
87+
Just as you do with [tuples](#deconstructing-tuple-elements-with-discards), you can use discards to ignore selected items returned by a `Deconstruct` method. Each discard is defined by a variable named "\_", and a single deconstruction operation can include multiple discards.
8988

9089
The following example deconstructs a `Person` object into four strings (the first and last names, the city, and the state) but discards the last name and the state.
9190

0 commit comments

Comments
 (0)