Skip to content

Commit

Permalink
Fix rules for tuple assignment. (dotnet#2027)
Browse files Browse the repository at this point in the history
* Fix rules for assignment.

Implicit conversions are considered in addition to identity conversions.

* Remove unnecessary comment.
  • Loading branch information
BillWagner authored Apr 26, 2017
1 parent afd44bd commit c23698e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/csharp/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ the rules for assigning named tuples to each other.
## Assignment and tuples

The language supports assignment between tuple types that have
the same number of fields and the same types for each of those
fields. Those types must be exact compile-time matches. Other
the same number of fields and implicit conversions for the types for each of those
fields. Other
conversions are not considered for assignments. Let's look at the kinds
of assignments that are allowed between tuple types.

Expand Down
6 changes: 4 additions & 2 deletions samples/snippets/csharp/tuples/tuples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ private static void AssignmentStatements()
#endregion

#region 04_VariableAssignment
// unnamed to named:
unnamed = named;

// named to unnamed:
named = unnamed;
// 'named' still has fields that can be referred to
// as 'answer', and 'message':
Expand All @@ -72,6 +70,10 @@ private static void AssignmentStatements()
// The field names are not assigned. 'named' still has
// fields that can be referred to as 'answer' and 'message':
Console.WriteLine($"{named.Answer}, {named.Message}");

// With implicit conversions:
// int can be implicitly converted to long
(long, string) conversion = named;
#endregion

}
Expand Down

0 comments on commit c23698e

Please sign in to comment.