我想得到一个字符串的“强力列表”。所以给出了这个输入:
string[] s = new string[] { "a", "b", "c" } ;
该函数将返回:
string[] s = new string[] { "a", "b", "c", "ab", "ac", "bc", "abc" } ;
我该怎么做?
答案 0 :(得分:0)
试试这个:
string[] chars = new string[] { "a", "b", "c" };
List<string> result = new List<string>();
foreach (int i in Enumerable.Range(0, 4))
{
IEnumerable<string> coll = chars;
foreach (int j in Enumerable.Range(0, i))
{
coll = coll.SelectMany(s => chars, (c, r) => c + r);
}
result.AddRange(coll);
}