src/BetterLinq/WithIndexExtension.cs
/// <summary>
/// Adds the index of each item withing the collection
/// </summary>
/// <typeparam name="T">The type of the element</typeparam>
/// <param name="collection">The collection.</param>
/// <returns>An enumeration of an object containing the index and the corresponding element</returns>
Adds the index of each item withing the collection
Adds the index of each item withing the collection
public static IEnumerable<Indexed<T>> WithIndex<T>(this IEnumerable<T> collection)
        {
            if (collection == null)
            {
                yield break;
            }
            var i = 0;
            foreach (var item in collection)
            {
                yield return new Indexed<T>(i, item);
                i++;
            }
        }
public static IEnumerable < Indexed < T > > WithIndex < T > ( this IEnumerable < T > collection ) { if ( collection == null ) { yield break ; } var i = 0 ; foreach ( var item in collection ) { yield return new Indexed < T > ( i , item ) ; i ++ ; } }
Adds the index of each item withing the collection
Adds the index of each item withing the collection
An enumeration of an object containing the index and the corresponding element
An enumeration of an object containing the index and the corresponding element
IEnumerable<T>
this
collection
None
typeparam
The type of the element
The type of the element