The elements in the List are arranged in full and recursive mode is used. The Code is as follows:
Class Program {static void Main (string [] args) {List <int> list = new List <int> () {6, 7, 8 }; foreach (var p1 in Permutate (list, list. count) {foreach (var I in p1) Console. write (I. toString () + ""); Console. writeLine ();} string strTest = "Cary"; foreach (List <char> p2 in Permutate (strTest. toCharArray (). toList (), strTest. length) {string strTmp = new string (p2.ToArray (); Console. write (strTmp + "");} Console. writeLine ();} public static void CircleRight (IList seq, int count) {object tmp = seq [count-1]; seq. removeAt (count-1); seq. insert (0, tmp);} public static IEnumerable <IList> Permutate (IList seq, int count) {if (count = 1) yield return seq; else {for (int I = 0; I <count; I ++) {foreach (var perm in Permutate (seq, count-1) yield return perm; CircleRight (seq, count );}}