Closed DavidArno closed 7 years ago
For C# 7, as it'll use the new tuple syntax, or add earlier and make a breaking-change conversion to the tuple syntax in v3.
Add a new method to IEnumerable<T>:
IEnumerable<T>
public IEnumerable<(int index, T item)> Indexed(this IEnumerable<T> enumeration);
This can then be used in situations where the index, as well as the value, is needed when enumerating a collection:
for (var (index, item) in someCollection.Indexed()) { Console.WriteLIne($"Item {index}: {item}"); }
Included in the v3.0.0 release.
For C# 7, as it'll use the new tuple syntax, or add earlier and make a breaking-change conversion to the tuple syntax in v3.
Add a new method to
IEnumerable<T>
:This can then be used in situations where the index, as well as the value, is needed when enumerating a collection: