title: how to type Permutation for a given string in C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13778947/how-to-type-sets-for-a-given-string">How to type sets for a given string</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to type the permutation for a string 
  for example the string "123" should give me
  123 132 213 231 321 312 
  I need help to fix my code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace TestAAD
  {
  class Program
  {
      static int len = 0;
      static int lenPerm = 0;
      private static void Permutations(string str, string perm , int i)
      {
          if (i == len) Console.WriteLine(perm);
          for (int k = 0; k &lt; len; k++)
          {
               lenPerm = perm.Length;
              for (int j = 0; j &lt; lenPerm; j++)
              {
                  if ((perm[j] == str[(len - 1) - k]) &amp;&amp; (len-1-k&gt;0))
                      k++;
              }
              if((len-1-k) &gt;=0)
              Permutations(str, perm + str[(len - 1) - k], i++);
          }
      }
      static void Main(string[] args)
      {
          string st = "123";
          len = st.Length;
          Permutations(st, "",0);
      }
  }
  }
  </code></pre>
  
  <p>Please if anyone can help me , Please
  thanks all</p>