WindowLeftExtensionWindowLeftTSource Method

Creates a left-aligned sliding window of a given size over the source sequence.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<IList<TSource>> WindowLeft<TSource>(
	this IEnumerable<TSource> source,
	int size
)

Parameters

source  IEnumerableTSource
The sequence over which to create the sliding window.
size  Int32
Size of the sliding window.

Type Parameters

TSource
The type of the elements of source.

Return Value

IEnumerableIListTSource
A sequence representing each sliding window.

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

A window can contain fewer elements than size, especially as it slides over the end of the sequence.

This operator uses deferred execution and streams its results.

Example

C#
Console.WriteLine(
    Enumerable
        .Range(1, 5)
        .WindowLeft(3)
        .Select(w => "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average())
        .ToDelimitedString(Environment.NewLine));

// Output:
// AVG(1,2,3) = 2
// AVG(2,3,4) = 3
// AVG(3,4,5) = 4
// AVG(4,5) = 4.5
// AVG(5) = 5

See Also