Click or drag to resize

MoreEnumerableTagFirstLastTSource, TResult Method

Returns a sequence resulting from applying a function to each element in the source sequence with additional parameters indicating whether the element is the first and/or last of the sequence.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 2.3.0
Syntax
public static IEnumerable<TResult> TagFirstLast<TSource, TResult>(
	this IEnumerable<TSource> source,
	Func<TSource, bool, bool, TResult> resultSelector
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The source sequence.
resultSelector
Type: SystemFuncTSource, Boolean, Boolean, TResult
A function that determines how to project the each element along with its first or last tag.

Type Parameters

TSource
The type of the elements of source.
TResult
The type of the element of the returned sequence.

Return Value

Type: IEnumerableTResult
Returns the resulting sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. 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 operator uses deferred execution and streams its results.
Examples
var numbers = new[] { 123, 456, 789 };
var result = numbers.TagFirstLast((num, fst, lst) => new 
             { 
                 Number = num,
                 IsFirst = fst, IsLast = lst
             });
The result variable, when iterated over, will yield { Number = 123, IsFirst = True, IsLast = False }, { Number = 456, IsFirst = False, IsLast = False } and { Number = 789, IsFirst = False, IsLast = True } in turn.
See Also