Click or drag to resize
MoreEnumerable.RunLengthEncode<T> Method (IEnumerable<T>)
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.

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 2.0.0
Syntax
public static IEnumerable<KeyValuePair<T, int>> RunLengthEncode<T>(
	this IEnumerable<T> sequence
)

Parameters

sequence
Type: System.Collections.Generic.IEnumerable<T>
The sequence to run length encode

Type Parameters

T
The type of the elements in the sequence

Return Value

Type: IEnumerable<KeyValuePair<T, Int32>>
A sequence of KeyValuePair{T,int} where the 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 IEnumerable<T>. 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