TEnumerable.ToDictionary<TSource,TKey,TElement> Method

Overloads

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Creates a dictionary from a sequence according to a specified key selector function.

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a dictionary from a sequence according to a specified key selector function and key comparer.

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

Creates a dictionary from a sequence according to specified key selector and element selector functions.

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a dictionary from a sequence according to specified key selector and element selector functions.

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Creates a dictionary from a sequence according to a specified key selector function.

Delphi
class function ToDictionary<TSource,TKey>(const source: IEnumerable<TSource>; const keySelector: Func<TSource, TKey>): IOrderedDictionary<TKey,TSource>

Type Parameters

TSource

The type of the elements of source .

TKey

The type of the key returned by keySelector .

Parameters

source
IEnumerable<TSource>

A sequence to create a dictionary from.

keySelector
Func<TSource, TKey>

A function to extract a key from each element.

Returns

IOrderedDictionary<TKey, TSource>

A dictionary that contains keys and values. The values within each group are in the same order as in source.

Exceptions

source or keySelector is nil .

keySelector produces duplicate keys for two elements.

ToDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a dictionary from a sequence according to a specified key selector function and key comparer.

Delphi
class function ToDictionary<TSource,TKey>(const source: IEnumerable<TSource>; const keySelector: Func<TSource, TKey>; const comparer: IEqualityComparer<TKey>): IOrderedDictionary<TKey,TSource>

Type Parameters

TSource

The type of the elements of source .

TKey

The type of the key returned by keySelector .

Parameters

source
IEnumerable<TSource>

A sequence to create a dictionary from.

keySelector
Func<TSource, TKey>

A function to extract a key from each element.

comparer
IEqualityComparer<TKey>

An equality comparer to compare keys.

Returns

IOrderedDictionary<TKey, TSource>

A dictionary that contains keys and values. The values within each group are in the same order as in source.

Exceptions

source or keySelector is nil .

keySelector produces duplicate keys for two elements.

Remarks

If comparer is nil , the default equality comparer is used to compare keys.

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

Creates a dictionary from a sequence according to specified key selector and element selector functions.

Delphi
class function ToDictionary<TSource,TKey,TElement>(const source: IEnumerable<TSource>; const keySelector: Func<TSource, TKey>; const elementSelector: Func<TSource, TElement>): IOrderedDictionary<TKey,TElement>

Type Parameters

TSource

The type of the elements of source .

TKey

The type of the key returned by keySelector .

TElement

The type of the value returned by elementSelector .

Parameters

source
IEnumerable<TSource>

A sequence to create a dictionary from.

keySelector
Func<TSource, TKey>

A function to extract a key from each element.

elementSelector
Func<TSource, TElement>

A transform function to produce a result element value from each element.

Returns

IOrderedDictionary<TKey, TElement>

A dictionary that contains values of type TElement selected from the input sequence.

Exceptions

source or keySelector or elementSelector is nil .

keySelector produces duplicate keys for two elements.

ToDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a dictionary from a sequence according to specified key selector and element selector functions.

Delphi
class function ToDictionary<TSource,TKey,TElement>(const source: IEnumerable<TSource>; const keySelector: Func<TSource, TKey>; const elementSelector: Func<TSource, TElement>; const comparer: IEqualityComparer<TKey>): IOrderedDictionary<TKey,TElement>

Type Parameters

TSource

The type of the elements of source .

TKey

The type of the key returned by keySelector .

TElement

The type of the value returned by elementSelector .

Parameters

source
IEnumerable<TSource>

A sequence to create a dictionary from.

keySelector
Func<TSource, TKey>

A function to extract a key from each element.

elementSelector
Func<TSource, TElement>

A transform function to produce a result element value from each element.

comparer
IEqualityComparer<TKey>

An equality comparer to compare keys.

Returns

IOrderedDictionary<TKey, TElement>

A dictionary that contains values of type TElement selected from the input sequence.

Exceptions

source or keySelector or elementSelector is nil .

keySelector produces duplicate keys for two elements.

Remarks

If comparer is nil , the default equality comparer is used to compare keys.