Hi,
根据你的描述,我认为你的问题可以分为三步来解决。
1.你需要算出长度为3的所有组合。
2.你需要进行字符串内部排序。
3.去除掉不需要的字符串。
下面是我的具体代码,你可以看看。
class Program
{
static void Main(string[] args)
{
string a = "abcd";
var m = a.ToCharArray().AsEnumerable();
IEnumerable<IEnumerable<char>> result =
GetPermutations(m, 3);
char [] b;
string newstring;
List<string> list = new List<string>();
foreach (var item in result)
{
b = item.ToList().ToArray();
Array.Sort(b);
newstring = new string(b);
list.Add(newstring);
}
list = list.Distinct().ToList() ;
list.ForEach(s => Console.WriteLine(s));
Console.ReadKey();
}
static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length)
{
if (length == 1) return list.Select(t => new T[] { t });
return GetPermutations(list, length - 1)
.SelectMany(t => list.Where(e => !t.Contains(e)),
(t1, t2) => t1.Concat(new T[] { t2 }));
}
}
Result:

Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.