You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Extensions/ForeachExtensions.cs

23 lines
606 B

using System;
using System.Collections.Generic;
namespace Infrastructure.Extensions
{
public static class ForeachExtensions
{
public static List<(int i, TItem value)> Each<TItem>(this IEnumerable<TItem> 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;
}
}
}