Index - Kalkwst/Risotto GitHub Wiki

Definition

Returns a sequence of KeyValuePair<TKey, TValue> where the key is the zero-based index of the value in the source sequence.

In this page

Overloads

Overload Description
Index() Returns a sequence of KeyValuePair<TKey, TValue> where the key is the zero-based index of the value in the source sequence.
Index(int index) Returns a sequence of KeyValuePair<TKey, TValue> where the key is the zero-based index of the value in the source sequence. An additional parameter specifies the starting index.

Index()

Returns a sequence of KeyValuePair<TKey, TValue> where the key is the zero-based index of the value in the source sequence.

public static IEnumerable<KeyValuePair<int, TSource>> Index<TSource>(this IEnumerable<TSource> source);

Type Parameters

TSource
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

Returns

IEnumerable <KeyValuePair<int, TSource>>
A sequence of KeyValuePair<int, TSource> with the key being the index and value being the element at the specific index of the sequence.

Exceptions

ArgumentNullException
source is null

Example

The following code example demonstrates how to use Index() to index a sequence

int[] sourceNumbers = new int[]{1, 2, 3, 4, 5};
IEnumerable<KeyValuePair<int, int>> result = sourceNumbers.Index();
/**
=>[
    {0, 1},
    {1, 2},
    {2, 3},
    {3, 4},
    {4, 5}
]**/

`

Index(int index)

eturns a sequence of KeyValuePair<TKey, TValue> where the key is the zero-based index of the value in the source sequence. An additional parameter specifies the starting index.

public static IEnumerable<KeyValuePair<int, TSource>> Index<TSource>(this IEnumerable<TSource> source, int startIndex);

Type Parameters

TSource
The type of the elements of the sequences.

Parameters

source IEnumerable <TSource>
The source sequence.

startIndex Int32
The starting index.

Returns

IEnumerable <KeyValuePair<int, TSource>>
A sequence of KeyValuePair<int, TSource> with the key being the index and value being the element at the specific index of the sequence.

Exceptions

ArgumentNullException
source is null

Example

The following code example demonstrates how to use Index(int index) to index a sequence from a starting index.

IEnumerable<KeyValuePair<int, int>> result = new[] { 1, 2, 3 }.Index(10);
/**
=>[
    {10, 1},
    {11, 2},
    {12, 3}
]**/
⚠️ **GitHub.com Fallback** ⚠️