From b628d1da2336af1e2b942021077cf48dc7f3a42b Mon Sep 17 00:00:00 2001 From: Petr Kulikov <15279990+pkulikov@users.noreply.github.com> Date: Fri, 29 Jun 2018 20:58:55 +0200 Subject: [PATCH] Clarified when `foreach` can be used with `ref` --- docs/csharp/language-reference/keywords/foreach-in.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/csharp/language-reference/keywords/foreach-in.md b/docs/csharp/language-reference/keywords/foreach-in.md index 4a14bd6ebbb84..9b0799d538204 100644 --- a/docs/csharp/language-reference/keywords/foreach-in.md +++ b/docs/csharp/language-reference/keywords/foreach-in.md @@ -1,6 +1,6 @@ --- title: "foreach, in (C# Reference)" -ms.date: 06/28/2018 +ms.date: 06/29/2018 f1_keywords: - "foreach" - "foreach_CSharpKeyword" @@ -29,11 +29,11 @@ The following example shows usage of the `foreach` statement with an instance of The next example uses the `foreach` statement with an instance of the type, which doesn't implement any interfaces: -[!code-csharp-interactive[span example](~/samples/snippets/csharp/keywords/IterationKeywordsExamples.cs#2)] +[!code-csharp[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. +Beginning with C# 7.3, if the enumerator's `Current` property returns a [reference return value](../../programming-guide/classes-and-structs/ref-returns.md) (`ref T` where `T` is the type of the collection element), 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. -[!code-csharp-interactive[ref span example](~/samples/snippets/csharp/keywords/IterationKeywordsExamples.cs#RefSpan)] +[!code-csharp[ref span example](~/samples/snippets/csharp/keywords/IterationKeywordsExamples.cs#RefSpan)] ## C# language specification @@ -47,4 +47,4 @@ Beginning with C# 7.3, when the collection type supports `ref` access to its ele [Iteration Statements](iteration-statements.md) [C# Keywords](index.md) [C# Reference](../index.md) -[C# Programming Guide](../../programming-guide/index.md) \ No newline at end of file +[C# Programming Guide](../../programming-guide/index.md)