MoreEnumerablePermutationsT Method

Generates a sequence of lists that represent the permutations of the original sequence.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<IList<T>> Permutations<T>(
	this IEnumerable<T> sequence
)

Parameters

sequence  IEnumerableT
The original sequence to permute.

Type Parameters

T
The type of the elements in the sequence.

Return Value

IEnumerableIListT
A sequence of lists representing permutations of the original sequence.

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

A permutation is a unique re-ordering of the elements of the sequence.

This operator returns permutations in a deferred, streaming fashion; however, each permutation is materialized into a new list. There are N! permutations of a sequence, where N ⇒ sequence.Count().

Be aware that the original sequence is considered one of the permutations and will be returned as one of the results.

Exceptions

OverflowException Too many permutations (limited by MaxValue); thrown during iteration of the resulting sequence.

See Also