CountDownExtensionCountDownT, TResult Method

Provides a countdown counter for a given count of elements at the tail of the sequence where zero always represents the last element, one represents the second-last element, two represents the third-last element and so on.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<TResult> CountDown<T, TResult>(
	this IEnumerable<T> source,
	int count,
	Func<T, int?, TResult> resultSelector
)

Parameters

source  IEnumerableT
The source sequence.
count  Int32
Count of tail elements of source to count down.
resultSelector  FuncT, NullableInt32, TResult
A function that receives the element and the current countdown value for the element and which returns those mapped to a result returned in the resulting sequence. For elements before the last count, the countdown value is null.

Type Parameters

T
The type of elements of source
TResult
The type of elements of the resulting sequence.

Return Value

IEnumerableTResult
A sequence of results returned by resultSelector.

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).

Remarks

This method uses deferred execution semantics and streams its results. At most, count elements of the source sequence may be buffered at any one time unless source is a collection or a list.

See Also