MapIndexed2

Builds a new collection whose elements are the results of applying the given mapping function to each pair of the elements of the collections.

The integer index passed to the function indicates the index (from 0) of element being transformed.

Parameters

Returns

Func<int, T, T2, TResult> mapping

IEnumerable<T> source

IEnumerable<T2> source2

IEnumerable<TResult>

Usage

Multiplying the sum of each pair of values by its index

//IEnumerable<int> source =  { 1, 2, 3 }
//IEnumerable<int> source2 = { 4, 5, 6 }

IEnumerable<int> result = 
    source.MapIndexed2(
        source2, 
        (index, value1, value2) => (value1 + value2) * index);

//result = { 0, 7, 18}

Last updated