From 069953e0bd9043e7f54855b959a1503a5297bb57 Mon Sep 17 00:00:00 2001 From: Alvin Christian Quijano Date: Tue, 15 Jan 2019 16:57:39 -0500 Subject: [PATCH] Added information (#26367) Added information to foreach loop. Indicated foreach loop is read only. --- guide/english/csharp/foreach/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guide/english/csharp/foreach/index.md b/guide/english/csharp/foreach/index.md index 11cb499221..b2d299159b 100644 --- a/guide/english/csharp/foreach/index.md +++ b/guide/english/csharp/foreach/index.md @@ -6,6 +6,8 @@ title: Foreach Loop The `foreach` loop executes a block of code for each item in a collection. The benefit of the `foreach` loop is you need not know how many items are within the collection to iterate through it; you simply tell your `foreach` loop to loop through the collection, as long as there are items within it. It is useful for iterating through lists, arrays, datatables, IEnumerables and other list-like data structures. It can be less efficient than a very well designed `for` loop, but the difference is negligible in most cases. +It is worth noting however, that when a `foreach` loop iterates through a data structure, each variable is read-only. Ideally, when you want to modify data in a loop, a `for` loop is the better choice. + ### Example ```csharp