Anonymous user
Permutations: Difference between revisions
1) Needs to be in special class for extensions. 2) T needs to be scoped to class.
(Added Wren) |
(1) Needs to be in special class for extensions. 2) T needs to be scoped to class.) |
||
Line 2,024:
Recursive Linq
{{works with|C sharp|C#|7}}
<lang csharp>public static
{
public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> values) where T : class
{
return new [] {values};▼
return values.SelectMany(v => Permutations(values.Where(x => x != v)), (v, p) => p.Prepend(v));
}
}</lang>
Usage
|