Skip to content

Conversation

@BillWagner
Copy link
Member

Fixes #5707

Relies on dotnet/samples#146

@BillWagner BillWagner requested review from mairaw and rpetrusha June 28, 2018 20:28
@BillWagner BillWagner added the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label Jun 28, 2018
@BillWagner
Copy link
Member Author

closing and reopening for a new build.

@BillWagner BillWagner closed this Jun 28, 2018
@BillWagner BillWagner reopened this Jun 28, 2018
@BillWagner BillWagner removed the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label Jun 28, 2018
Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one suggested rewording. @BillWagner. Otherwise, this is ready to merge.


[!code-csharp-interactive[span example](~/samples/snippets/csharp/keywords/IterationKeywordsExamples.cs#2)]

Beginning with C# 7.3, when the collection type supports `ref` access to its elements, you can declare the iteration variable with the `ref` or `ref readonly` modifier. The following example shows iteration using a `ref` iteration variable to set the value of each item in a stackalloc array. The `ref readonly` version iterates the collection to print all the values. The `readonly` declaration uses an implicit local variable declaration. Implicit variable declarations can be used with either `ref` or `ref readonly` declarations, as can explicitly typed variable declarations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following example... -> The following example uses a ref iteration variable to set the value...

@BillWagner BillWagner merged commit 3b153af into dotnet:master Jun 28, 2018
@BillWagner BillWagner deleted the foreach-ref-reassignment branch June 28, 2018 21:42

[!code-csharp-interactive[span example](~/samples/snippets/csharp/keywords/IterationKeywordsExamples.cs#2)]

Beginning with C# 7.3, when the collection type supports `ref` access to its elements, you can declare the iteration variable with the `ref` or `ref readonly` modifier. The following example uses a `ref` iteration variable to set the value of each item in a stackalloc array. The `ref readonly` version iterates the collection to print all the values. The `readonly` declaration uses an implicit local variable declaration. Implicit variable declarations can be used with either `ref` or `ref readonly` declarations, as can explicitly typed variable declarations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner

...when the collection type supports ref access to its elements...

Should that be clarified? How do I know when the collection type supports ref access to the elements? Is the only sufficient condition is that the Current property returns ref T (or it's just one of several)? If yes, is it fine to rephrase the following way:

Beginning with C# 7.3, when the Current property returns ref T where T is the type of the collection element, you can declare the iteration variable with the ref or ref readonly modifier.

I don't like mentioning the Current property here. However, that is introduced anyway at the start of the topic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkulikov Your proposed change is great. Would you like to submit a PR for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner I'll create a PR with the change today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants