MoreEnumerable.RunLengthEncode<T> Method (IEnumerable<T>, IEqualityComparer<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. This overload
uses a custom equality comparer to identify equivalent items.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntaxpublic static IEnumerable<KeyValuePair<T, int>> RunLengthEncode<T>(
this IEnumerable<T> sequence,
IEqualityComparer<T> comparer
)
<ExtensionAttribute>
Public Shared Function RunLengthEncode(Of T) (
sequence As IEnumerable(Of T),
comparer As IEqualityComparer(Of T)
) As IEnumerable(Of KeyValuePair(Of T, Integer))
public:
[ExtensionAttribute]
generic<typename T>
static IEnumerable<KeyValuePair<T, int>>^ RunLengthEncode(
IEnumerable<T>^ sequence,
IEqualityComparer<T>^ comparer
)
[<ExtensionAttribute>]
static member RunLengthEncode :
sequence : IEnumerable<'T> *
comparer : IEqualityComparer<'T> -> IEnumerable<KeyValuePair<'T, int>>
Parameters
- sequence
- Type: System.Collections.Generic.IEnumerable<T>
The sequence to run length encode - comparer
- Type: System.Collections.Generic.IEqualityComparer<T>
The comparer used to identify equivalent items
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 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
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