There is no such design for updating the cycle; the iterator is read-only. For example, the following provides a perfectly valid iterator:
public IEnumerable<int> Get1Thru5() { yield return 1; yield return 2; yield return 3; yield return 4; yield return 5; }
How will it be updated? What will update?
If the data is an array / list / etc, then something like:
for(int i = 0 ; i < arr.Length ; i++) { arr[i] = "new value"; }
Or other parameters depending on the specific container.
Update; when click , extension method:
public static void UpdateAll<T>(this IList<T> list, Func<T, T> operation) { for (int i = 0; i < list.Count; i++) { list[i] = operation(list[i]); } } static void Main() { string[] arr = { "abc", "def", "ghi" }; arr.UpdateAll(s => "new value"); foreach (string s in arr) Console.WriteLine(s); }
Marc gravell
source share