RunLengthEncodeExtensionRunLengthEncodeT(IEnumerableT, IEqualityComparerT) Method

Run-length encodes a sequence by converting consecutive instances of the same element into a KeyValuePair{T,int} representing the item and its occurrence count. This overload uses a custom equality comparer to identify equivalent items.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<KeyValuePair<T, int>> RunLengthEncode<T>(
	this IEnumerable<T> sequence,
	IEqualityComparer<T>? comparer
)

Parameters

sequence  IEnumerableT
The sequence to run length encode
comparer  IEqualityComparerT
The comparer used to identify equivalent items

Type Parameters

T
The type of the elements in the sequence

Return Value

IEnumerableKeyValuePairT, Int32
A sequence of KeyValuePair{T,int} where they key is the element and the value is the occurrence count

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also