using System; using System.Collections.Generic; namespace Infrastructure.Extensions { public static class ForeachExtensions { public static List<(int i, TItem value)> Each(this IEnumerable items) { if (items is null) { throw new ArgumentNullException(nameof(items)); } var result = new List<(int i, TItem value)>(); var index = 0; foreach (var item in items) { result.Add((index++, item)); } return result; } } }