using System.Collections;
using System.Collections.Generic;
public static void Main(string[] args)
var permutations = Permutations<int>(new List<int> { 1, 2, 3 });
foreach(var perm in permutations)
Console.WriteLine(string.Join(",", perm.Select(p=>p.ToString()).ToArray()));
public static ICollection<ICollection<T>> Permutations<T>(ICollection<T> list) {
var result = new List<ICollection<T>>();
foreach (var element in list) {
var remainingList = new List<T>(list);
remainingList.Remove(element);
foreach (var permutation in Permutations<T>(remainingList)) {
permutation.Add(element);