且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linq 中的组合生成器

更新时间:2022-01-03 09:05:31

对于它的价值,尝试这样的事情:

For what it's worth, try something like this:

public static IEnumerable<string> GetPermutations(string s)
{
    if (s.Length > 1)
        return from ch in s
               from permutation in GetPermutations(s.Remove(s.IndexOf(ch), 1))
               select string.Format("{0}{1}", ch, permutation);

    else
        return new string[] { s };
}